1 | ;####################################################################### |
---|
2 | ;# Program language: IDL (Interactive Data Language), file-ending .pro # |
---|
3 | ;# # |
---|
4 | ;# This program checks the content of netCDF-files generated by PALM # |
---|
5 | ;# and displays it on the standard output (console). # |
---|
6 | ;# The program provides the following: # |
---|
7 | ;# 1. Variables of the netCDF-file # |
---|
8 | ;# 2. The Dimensions of the variables # |
---|
9 | ;# 3. The type of the variable (float, double, ..) # |
---|
10 | ;# 4. The unit of the variable (e.g. m/s) # |
---|
11 | ;# (5. In case of timeseries-data (ts) the mean time step of the run) # |
---|
12 | ;# # |
---|
13 | ;# coder: F. Herbort # |
---|
14 | ;####################################################################### |
---|
15 | ; # |
---|
16 | ; ENTER PARAMETERS: # |
---|
17 | ; ================= # |
---|
18 | ; # |
---|
19 | ; Host-Identifier: # |
---|
20 | hostid = 'lcsgih' ; # |
---|
21 | ; # |
---|
22 | ; Name of run: # |
---|
23 | name_of_run = 'example_cbl' ; sub-folder of # |
---|
24 | ; ~/palm/current_version/JOBS # |
---|
25 | ; Number for restart-files: # |
---|
26 | resnum = ' ' ; (blank if no restart-file is considered) # |
---|
27 | ; # |
---|
28 | ; Path to netCDF-file: # |
---|
29 | netcdf_path = '/home/herbort/palm/current_version/JOBS/'+name_of_run+'/OUTPUT/' ;# |
---|
30 | ; # |
---|
31 | ; Kind of data: # |
---|
32 | kind_data = 'pr' ; # |
---|
33 | ; ts --> timeseries # |
---|
34 | ; pr --> profiles # |
---|
35 | ; sp --> spectra # |
---|
36 | ; xy --> xy cross-section # |
---|
37 | ; 3d --> 3d data # |
---|
38 | ; 3d_av --> time-averaged 3d data # |
---|
39 | ; . . # |
---|
40 | ; . . # |
---|
41 | ; # |
---|
42 | ;####################################################################### |
---|
43 | |
---|
44 | PRINT, ' ' |
---|
45 | PRINT, '========================================================' |
---|
46 | PRINT, 'Program checks content of netCDF-files generated by PALM' |
---|
47 | PRINT, ' [F. Herbort]' |
---|
48 | PRINT, '========================================================' |
---|
49 | PRINT, ' ' |
---|
50 | |
---|
51 | ;======================================================================= |
---|
52 | ; Checking existence of file: |
---|
53 | ; --------------------------- |
---|
54 | |
---|
55 | IF resnum EQ ' ' THEN datafile = hostid+'_'+name_of_run+'_'+kind_data+'.nc' |
---|
56 | IF resnum NE ' ' THEN datafile = hostid+'_'+name_of_run+'_'+kind_data+'.'+resnum+'.nc' |
---|
57 | input = netcdf_path+datafile |
---|
58 | |
---|
59 | fileyn = FILE_TEST(input) |
---|
60 | |
---|
61 | ; Checking, wether filename is without hostid at the beginning of filename: |
---|
62 | IF fileyn EQ 0L THEN BEGIN |
---|
63 | IF resnum EQ ' ' THEN datafile = name_of_run+'_'+kind_data+'.nc' |
---|
64 | IF resnum NE ' ' THEN datafile = name_of_run+'_'+kind_data+'.'+resnum+'.nc' |
---|
65 | input = netcdf_path+datafile |
---|
66 | fileyn = FILE_TEST(input) |
---|
67 | ENDIF |
---|
68 | |
---|
69 | IF fileyn EQ 0L THEN BEGIN |
---|
70 | PRINT, 'netCDF-file does not exist!' |
---|
71 | PRINT, 'Program aborted' |
---|
72 | PRINT, ' ' |
---|
73 | GOTO, abort_flag |
---|
74 | ENDIF |
---|
75 | |
---|
76 | ;======================================================================= |
---|
77 | ; Checking the netCDF-file: |
---|
78 | ; ------------------------- |
---|
79 | |
---|
80 | nid = NCDF_OPEN(input) |
---|
81 | |
---|
82 | PRINT, 'Opened netCDF-file ', input |
---|
83 | |
---|
84 | info_n = NCDF_INQUIRE(nid) |
---|
85 | |
---|
86 | PRINT, ' ' |
---|
87 | PRINT, info_n.Nvars, ' variables existing:', FORMAT = '(I2,A20)' |
---|
88 | PRINT, ' ' |
---|
89 | PRINT, 'No. Variable Dimensions Type Unit' |
---|
90 | PRINT, '--- -------- ---------- ---- ----' |
---|
91 | |
---|
92 | FOR n1 = 0, info_n.Nvars - 1 DO BEGIN |
---|
93 | vars = NCDF_VARINQ(nid,n1) |
---|
94 | |
---|
95 | dimens = vars.Ndims |
---|
96 | |
---|
97 | IF dimens EQ 0 THEN str_dims = 'scalar' |
---|
98 | |
---|
99 | IF dimens GE 1 THEN BEGIN |
---|
100 | |
---|
101 | dimarr = LONARR(dimens) |
---|
102 | |
---|
103 | FOR cc = 0, dimens - 1 DO BEGIN |
---|
104 | NCDF_DIMINQ, nid, vars.Dim(cc), dimename, dim_size |
---|
105 | |
---|
106 | dimarr(cc) = dim_size |
---|
107 | |
---|
108 | ENDFOR |
---|
109 | |
---|
110 | IF dimens EQ 1 THEN str_dims = '('+STRING(dimarr(0), FORMAT = '(I4)')+')' |
---|
111 | IF dimens EQ 1 AND kind_data EQ 'ts' THEN str_dims = '('+STRING(dimarr(0), FORMAT = '(I6)')+')' |
---|
112 | IF dimens EQ 2 THEN str_dims = '('+STRING(dimarr(0), FORMAT = '(I4)')+','+STRING(dimarr(1), FORMAT = '(I4)')+')' |
---|
113 | IF dimens EQ 3 THEN str_dims = '('+STRING(dimarr(0), FORMAT = '(I4)')+','+STRING(dimarr(1), $ |
---|
114 | FORMAT = '(I4)')+','+STRING(dimarr(2), FORMAT = '(I4)')+')' |
---|
115 | IF dimens EQ 4 THEN str_dims = '('+STRING(dimarr(0), FORMAT = '(I4)')+','+STRING(dimarr(1), $ |
---|
116 | FORMAT = '(I4)')+','+STRING(dimarr(2), FORMAT = '(I4)')+','+STRING(dimarr(3), FORMAT = '(I4)')+')' |
---|
117 | IF dimens GT 4 THEN str_dims = '> 4-dimensional' |
---|
118 | |
---|
119 | ENDIF |
---|
120 | |
---|
121 | attdims = vars.Natts |
---|
122 | |
---|
123 | IF attdims GE 1 THEN BEGIN |
---|
124 | FOR aa = 0, attdims - 1 DO BEGIN |
---|
125 | |
---|
126 | attr_name = NCDF_ATTNAME(nid,n1,aa) |
---|
127 | |
---|
128 | IF attr_name EQ 'units' THEN BEGIN |
---|
129 | NCDF_ATTGET, nid, n1, 'units', unit_byte |
---|
130 | |
---|
131 | res = SIZE(unit_byte, /DIMENSION) |
---|
132 | num_letters = res(0) |
---|
133 | |
---|
134 | unit = '' |
---|
135 | IF num_letters GT 0 THEN BEGIN |
---|
136 | FOR ll = 0, num_letters - 1 DO BEGIN |
---|
137 | unit = unit+STRING(unit_byte(ll)) |
---|
138 | ENDFOR |
---|
139 | ENDIF |
---|
140 | IF num_letters EQ 0 THEN unit = STRING(unit_byte) |
---|
141 | |
---|
142 | ;HELP, unit |
---|
143 | ENDIF |
---|
144 | |
---|
145 | ENDFOR |
---|
146 | ENDIF |
---|
147 | |
---|
148 | PRINT, n1+1, vars.Name, str_dims, vars.DataType, unit, FORMAT = '(I2,4X,A14,3X,A21,5X,A7,7X,A7)' |
---|
149 | |
---|
150 | IF vars.Name EQ 'time' THEN BEGIN |
---|
151 | NCDF_VARGET, nid, vars.Name, time |
---|
152 | ENDIF |
---|
153 | |
---|
154 | ENDFOR |
---|
155 | |
---|
156 | IF kind_data EQ 'ts' THEN BEGIN |
---|
157 | |
---|
158 | ; Determining the mean time step of the run: |
---|
159 | PRINT, ' ' |
---|
160 | dim_time = N_ELEMENTS(time) |
---|
161 | time_diff = FLTARR(dim_time-2L) |
---|
162 | time_diff(*) = time(2L:dim_time-1L) - time(1L:dim_time-2L) |
---|
163 | |
---|
164 | mean_time_step = MEAN(time_diff) |
---|
165 | sigma_time_step = SQRT(VARIANCE(time_diff)) |
---|
166 | |
---|
167 | PRINT, ' ' |
---|
168 | PRINT, 'Mean time step of the run: ', mean_time_step, ' s + - ', $ |
---|
169 | sigma_time_step, ' s', FORMAT = '(A27,F4.2,A7,F4.2,A2)' |
---|
170 | PRINT, ' ' |
---|
171 | |
---|
172 | IF dim_time GT 30 THEN BEGIN |
---|
173 | |
---|
174 | time_diff = time_diff(19L:dim_time-3L) |
---|
175 | |
---|
176 | mean_time_step = MEAN(time_diff) |
---|
177 | sigma_time_step = SQRT(VARIANCE(time_diff)) |
---|
178 | |
---|
179 | PRINT, ' ' |
---|
180 | PRINT, 'Mean time step of the run (but from the 20th time step): ', mean_time_step, ' s + - ', $ |
---|
181 | sigma_time_step, ' s', FORMAT = '(A57,F4.2,A7,F4.2,A2)' |
---|
182 | PRINT, ' ' |
---|
183 | |
---|
184 | ENDIF |
---|
185 | |
---|
186 | ENDIF |
---|
187 | |
---|
188 | |
---|
189 | PRINT, ' ' |
---|
190 | |
---|
191 | NCDF_CLOSE, nid |
---|
192 | |
---|
193 | PRINT, 'Program finished' |
---|
194 | abort_flag: |
---|
195 | PRINT, ' ' |
---|
196 | |
---|
197 | |
---|
198 | END |
---|