doc/app/idl: plot_xz_palm_output.pro

File plot_xz_palm_output.pro, 10.4 KB (added by herbort, 13 years ago)
Line 
1;#######################################################################
2;# Program language: IDL (Interactive Data Language), file-ending .pro #
3;#                                                                     #
4;# This program creates png- or ps-images from netCDF-files generated  #
5;# by PALM. The images show xz cross sections of an available variable.#
6;#                                                                     #
7;# Remarks:                                                            #
8;#   * Program reads netCDF files ending with *_xz.nc (PALM xz slices) #
9;#   * The input-parameters, that the program requires, have to be     #
10;#     entered in the following section "ENTER PARAMETERS".            #
11;#   * The program creates a .png or .ps image in the current directory#
12;#                                                                     #
13;#                                                   coder: F. Herbort #
14;#######################################################################
15;                                                                      #
16; ENTER PARAMETERS:                                                    #
17; =================                                                    #
18;                                                                      #
19; Host-Identifier:                                                     #
20hostid = 'lcsgih'   ;                                                  #
21;                                                                      #
22; Name of run:                                                         #
23name_of_run = 'example_cbl'   ; sub-folder of                          #
24;                               ~/palm/current_version/JOBS            #
25; Number for restart-files:                                            #
26resnum = ' '   ; (blank if no restart-file is considered)              #
27;                                                                      #
28; Path to netCDF-file:                                                 #
29netcdf_path = '/home/herbort/palm/current_version/JOBS/'+name_of_run+'/OUTPUT/' ;#
30;                                                                      #
31; Point of time [s]:                                                   #
32t_point = 3604   ;                                                     #
33;                                                                      #
34; Chosing desired variables (0 = no, 1 = yes):                         #
35pt_yn = 1     ; potential temperature                                  #
36w_yn = 1     ; vertical wind velocity                                  #
37;                                                                      #
38; time-averaged data? (0 = no, 1 = yes):                               #
39av_yn = 0   ;                                                          #
40;                                                                      #
41; isotropic x- and z-axis? (0 = no, 1 = yes):                          #
42iso_yn = 0   ;                                                         #
43;                                                                      #
44; kind of image (.png or .ps):                                         #
45png_yn = 1   ;                                                         #
46ps_yn = 0    ;                                                         #
47;#######################################################################
48
49PRINT, ' '
50PRINT, '==========================================================='
51PRINT, 'Program creates images from netCDF-files generated by PALM.'
52PRINT, 'The images show xz cross sections of different variables.  '
53PRINT, '                                               [F. Herbort]'
54PRINT, '==========================================================='
55PRINT, ' '
56
57;=======================================================================
58; Constants and parameters:
59; -------------------------
60
61IF av_yn EQ 0 THEN kind_data = 'xz'
62IF av_yn NE 0 THEN kind_data = 'xz_av'
63
64;=======================================================================
65; Checking existence of file:
66; ---------------------------
67
68IF resnum EQ ' ' THEN datafile = hostid+'_'+name_of_run+'_'+kind_data+'.nc'
69IF resnum NE ' ' THEN datafile = hostid+'_'+name_of_run+'_'+kind_data+'.'+resnum+'.nc'
70input = netcdf_path+datafile
71
72fileyn = FILE_TEST(input)
73
74; Checking, wether filename is without hostid at the beginning of filename:
75IF fileyn EQ 0L THEN BEGIN
76IF resnum EQ ' ' THEN datafile = name_of_run+'_'+kind_data+'.nc'
77IF resnum NE ' ' THEN datafile = name_of_run+'_'+kind_data+'.'+resnum+'.nc'
78input = netcdf_path+datafile
79fileyn = FILE_TEST(input)
80ENDIF
81
82IF fileyn EQ 0L THEN BEGIN
83PRINT, 'netCDF-file does not exist!'
84PRINT, 'Program aborted'
85PRINT, ' '
86GOTO, abort_flag
87ENDIF
88
89;=======================================================================
90; Reading the profile data from netCDF-file:
91; ------------------------------------------
92
93nid = NCDF_OPEN(input)
94
95NCDF_VARGET, nid, 'time', time
96NCDF_VARGET, nid, 'x', x_vals
97NCDF_VARGET, nid, 'zu', zu_vals
98NCDF_VARGET, nid, 'zw', zw_vals
99NCDF_VARGET, nid, 'y_xz', y_xz
100IF pt_yn NE 0 THEN NCDF_VARGET, nid, 'pt_xz', pt
101IF w_yn NE 0 THEN NCDF_VARGET, nid, 'w_xz', w
102
103NCDF_CLOSE, nid
104
105PRINT, 'xz data read in'
106PRINT, ' '
107
108; Determing horizontal and vertical dimensions:
109res = SIZE(x_vals, /DIMENSION)
110nx = res(0)
111res = SIZE(zu_vals, /DIMENSION)
112nz = res(0)
113res = SIZE(y_xz, /DIMENSION)
114nsl = res(0)
115
116;=======================================================================
117; Finding the time point:
118; -----------------------
119
120tt = WHERE(ROUND(time) EQ FIX(t_point))
121
122IF tt(0) EQ -1 THEN tt = WHERE(FIX(t_point) - 1 EQ ROUND(time))
123IF tt(0) EQ -1 THEN tt = WHERE(FIX(t_point) + 1 EQ ROUND(time))
124IF tt(0) EQ -1 THEN tt = WHERE(FIX(t_point) - 2 EQ ROUND(time))
125IF tt(0) EQ -1 THEN tt = WHERE(FIX(t_point) + 2 EQ ROUND(time))
126
127IF tt(0) EQ -1 THEN BEGIN
128PRINT, 'Desired time point not possible!'
129PRINT, 'Program aborted'
130PRINT, ' '
131GOTO, abort_flag
132ENDIF
133
134tt = tt(0)
135
136time_sec = STRING(time(tt), FORMAT = '(I5.5)')
137
138;=======================================================================
139; Choosing the xz-slice:
140; ----------------------
141
142IF nsl GT 1 THEN BEGIN
143PRINT, nsl, ' xz-slices exist:', FORMAT = '(I2,A17)'
144PRINT, '-------------------'
145FOR aa = 0, nsl - 1 DO BEGIN
146PRINT, aa+1, ' ', y_xz(aa), ' m', FORMAT = '(I2,A1,F7.1,A2)'
147ENDFOR
148PRINT, ' '
149slice_flag:
150PRINT, 'Choose a slice (type 1 for slice 1, 2 for slice 2, ...):'
151READ, sl
152IF (sl GT nsl) OR (sl LT 1) THEN BEGIN
153PRINT, 'Type a number between 1 and ', nsl, FORMAT = '(A28,I2)'
154GOTO, slice_flag
155ENDIF
156PRINT, ' '
157sl = FIX(sl) - 1
158slice_txt = STRING(y_xz(sl), FORMAT = '(I5.5)')
159slice_txt = slice_txt+'m'
160IF y_xz(sl) EQ -1.0 THEN slice_txt = 'yav'
161ENDIF
162
163IF nsl LE 1 THEN BEGIN
164sl = 0
165slice_txt = STRING(y_xz, FORMAT = '(I5.5)')
166ENDIF
167
168;=======================================================================
169; Plotting the data:
170; ------------------
171
172SET_PLOT, 'Z'
173DEVICE, Z_BUFFERING = 0, SET_RESOLUTION=[1200,900]
174SET_COLORS=256
175
176LOADCT, 0
177TVLCT, R,G,B, /GET
178
179!P.CHARSIZE = 2.3
180!P.CHARTHICK = 2.3
181!X.THICK = 3.0
182!Y.THICK = 3.0
183!X.TICKLEN = 0.025
184!Y.TICKLEN = 0.01
185
186black = 0
187white = 255
188!P.BACKGROUND = white
189
190plot_window = [0.12,0.10,0.96,0.99]
191
192; .ps-preferences, if desired:
193IF ps_yn NE 0 THEN BEGIN
194SET_PLOT, 'PS'
195PRINT, 'Postscript-Format (.ps) selected'
196PRINT, ''
197;Farbeinstellungen, Format etc.:
198;DEVICE, /COLOR, BITS = 8, ENCAPSULATED = 1, /ISOLATIN1, /PORTRAIT
199;DEVICE, FILENAME = plotpath+plotfile+'.eps'
200DEVICE, /COLOR, BITS = 8, ENCAPSULATED = 0, /ISOLATIN1, /LANDSCAPE
201;DEVICE, SCALE_FACTOR = 1.0, XOFFSET = 1.0, YOFFSET = 1.0
202!P.CHARSIZE = 1.5
203!P.CHARTHICK = 1.5
204;plot_window = [0.095,0.225,0.97,0.99]
205c_char_size = 1.1
206c_char_thick = 1.0
207ENDIF
208
209; Determining x- and z-ranges of the plot:
210x_min = FLOOR(MIN(x_vals)/100.0)*100.0
211x_max = FLOOR(MAX(x_vals)/100.0)*100.0
212IF x_max LE 5000.0 THEN BEGIN
213x_inter = 500.0
214x_minor = 5
215ENDIF
216IF x_max GT 5000.0 THEN BEGIN
217x_inter = 1000.0
218x_minor = 2
219ENDIF
220IF x_max GT 10000.0 THEN BEGIN
221x_inter = 5000.0
222x_minor = 5
223ENDIF
224
225z_min = FLOOR(MIN(zu_vals)/100.0)*100.0
226z_max = FLOOR(MAX(zu_vals)/100.0)*100.0
227z_inter = 500.0
228z_minor = 5
229
230IF pt_yn NE 0 THEN BEGIN   ; pt
231
232IF av_yn EQ 0 THEN plotfile = 'pt_'+slice_txt+'_'+time_sec+'s_'+name_of_run+'_idl_xz'
233IF av_yn NE 0 THEN plotfile = 'pt_av_'+slice_txt+'_'+time_sec+'s_'+name_of_run+'_idl_xz'
234
235IF ps_yn NE 0 THEN DEVICE, FILENAME = plotfile+'.ps'
236
237c_levs = FINDGEN(101)*1.0 + 240.0   ; Contours every 1 K
238c_labs = INTARR(101)
239c_labs(*) = 1
240pt_xz = FLTARR(nx,nz)
241pt_xz(*,*) = pt(*,sl,*,tt)
242IF iso_yn NE 0 THEN iso_yn = 1
243IF png_yn NE 0 THEN BEGIN
244c_char_size = 1.5
245c_char_thick = 1.0
246ENDIF
247
248; Plotting:
249CONTOUR, pt_xz, x_vals, zu_vals, COLOR = black, XRANGE = [x_min,x_max], YRANGE = [z_min,z_max], $
250XMINOR = x_minor, YMINOR = z_minor, XTITLE = 'x [m]', YTITLE = 'altitude [m]', $
251XTICKINTERVAL = x_inter, YTICKINTERVAL = z_inter, POSITION = plot_window, $
252XSTYLE = 1, YSTYLE = 1, XTICKFORMAT = '(I5)', YTICKFORMAT = '(I4)', LEVELS = c_levs, C_LABELS = c_labs, $
253C_CHARSIZE = c_char_size, C_CHARTHICK = c_char_thick, ISOTROPIC = iso_yn
254
255IF png_yn NE 0 THEN BEGIN
256DATA = TVRD()
257WRITE_PNG, plotfile+'.png', DATA, r, g, b
258PRINT, 'png-image of xz cross section of "pt" created'
259;PRINT, ' '
260ENDIF
261
262DEVICE, /CLOSE
263ENDIF
264
265IF w_yn NE 0 THEN BEGIN   ; w
266
267IF av_yn EQ 0 THEN plotfile = 'w_'+slice_txt+'_'+time_sec+'s_'+name_of_run+'_idl_xz'
268IF av_yn NE 0 THEN plotfile = 'w_av_'+slice_txt+'_'+time_sec+'s_'+name_of_run+'_idl_xz'
269
270IF ps_yn NE 0 THEN DEVICE, FILENAME = plotfile+'.ps'
271
272c_levs_m = FINDGEN(60)*0.2 - 12.0   ; Contours every 0.2 m/s
273c_levs_p = FINDGEN(60)*0.2 + 0.2
274c_levs = [c_levs_m,c_levs_p]
275c_labs = INTARR(120)
276c_labs(*) = 1
277c_lines = INTARR(120)
278c_lines(0:59) = 1
279c_lines(60:119) = 0
280w_xz = FLTARR(nx,nz)
281w_xz(*,*) = w(*,sl,*,tt)
282IF iso_yn NE 0 THEN iso_yn = 1
283IF png_yn NE 0 THEN BEGIN
284c_char_size = 1.5
285c_char_thick = 1.0
286ENDIF
287
288; Plotting:
289CONTOUR, w_xz, x_vals, zu_vals, COLOR = black, XRANGE = [x_min,x_max], YRANGE = [z_min,z_max], $
290XMINOR = x_minor, YMINOR = z_minor, XTITLE = 'x [m]', YTITLE = 'altitude [m]', $
291XTICKINTERVAL = x_inter, YTICKINTERVAL = z_inter, POSITION = plot_window, $
292XSTYLE = 1, YSTYLE = 1, XTICKFORMAT = '(I5)', YTICKFORMAT = '(I4)', LEVELS = c_levs, C_LABELS = c_labs, $
293C_CHARSIZE = c_char_size, C_CHARTHICK = c_char_thick, C_LINESTYLE = c_lines, ISOTROPIC = iso_yn
294
295IF png_yn NE 0 THEN BEGIN
296DATA = TVRD()
297WRITE_PNG, plotfile+'.png', DATA, r, g, b
298PRINT, 'png-image of xz cross section of "w" created'
299;PRINT, ' '
300ENDIF
301
302DEVICE, /CLOSE
303ENDIF
304
305PRINT, ' '
306PRINT, 'Program finished'
307abort_flag:
308PRINT, ' '
309
310
311END