iconPlot 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/lib/icon_plot.ncl ADDED
@@ -0,0 +1,653 @@
1
+ ;---------------------------------------------------------------
2
+ ; This script makes contour/vector plots of general ICON data files
3
+ ; For scalar variables the underlying grid can be used instead of automatic
4
+ ; contour lines. Both modes are capable of masking the input files before
5
+ ; plotting, see the command line options below for details.
6
+
7
+ load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
8
+ load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
9
+ load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
10
+ load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/shea_util.ncl"
11
+
12
+ ;------- config ---------------------------------------------------------------
13
+ ; default settings from user file
14
+ CONFIGFILE = getenv("HOME")+"/.icon_plot.rc"
15
+ if (isfilepresent(CONFIGFILE)) then
16
+ print("Found configfile:"+CONFIGFILE)
17
+ loadscript(CONFIGFILE)
18
+ end if
19
+
20
+ if ( .not. isvar("altLibDir") ) then
21
+ print("load default library from /pool/data/ICON/tools")
22
+ loadscript("/pool/data/ICON/tools/icon_plot_lib.ncl")
23
+ else
24
+ print("Load library: "+altLibDir+"/icon_plot_lib.ncl")
25
+ loadscript(altLibDir +"/icon_plot_lib.ncl")
26
+ end if
27
+ ;--- end config ---------------------------------------------------------------
28
+ ;==============================================================================
29
+ ;----- MAIN PROGRAM -----------------------------------------------------------
30
+ if (isvar("help")) then
31
+ dq = str_get_dq()
32
+ print(";---------------------------------------------------------------")
33
+ print("; Basic Usage:")
34
+ print("; ncl icon_plot.ncl 'iFile=" + dq + "path/file.nc" + dq + "' 'varName=" + dq + "ELEV" + dq + "' 'oFile=" + dq + "test" + dq + "' timeStep=1 levIndex=1")
35
+ print(";")
36
+ print("; Select an special area of the globe with mapLLC (LowerLeftCorner) and mapURC (UpperRightCorner) ")
37
+ print("; ncl icon_plot.ncl 'iFile=" + dq + "path/file.nc" + dq + "' 'varName=" + dq + "W" + dq + "' 'mapLLC=(/35.0, -8/)' 'mapURC=(/55, 8/)'")
38
+ print(";")
39
+ print("; Masking:")
40
+ print("; ncl icon_plot.ncl 'iFile=" + dq + "oce_aqua_planet_O.R2B04L4_0001.nc" + dq + "' 'varName=" + dq + "ELEV" + dq + "' 'maskName=" + dq + "wet_c" + dq + "' ")
41
+ print("; ncl icon_plot.ncl 'iFile=" + dq + "oce.nc" + dq + "' 'varName=" + dq + "W" + dq + "' 'maskName=" + dq + "topo" + dq + "' 'maskFile=" + dq + "icon_mask.nc" + dq + "' ")
42
+ print(";")
43
+ print("; Vectorplot:")
44
+ print("; ncl icon_plot.ncl 'iFile=" + dq + "oce.nc" + dq + "' 'vecVars=" + dq + "u-veloc v-veloc" + dq + "' 'oFile=" + dq + "test" + dq + "'")
45
+ print(";")
46
+ print("; Vertical cross section:")
47
+ print("; ncl icon_plot.ncl 'iFile=" + dq + "iconOutput.nc" + dq + "' 'secLC=(/ 0.0,-90.0 /)' 'secRC=(/ 0.0,90.0/)' 'oType=" + dq + "png" + dq + "' 'rStrg=" + dq + "" + dq + "' 'tStrg=" + dq + "ICON coupled aqual planet" + dq + "'")
48
+ print(";")
49
+ print("; Overlay plot (vectors over contour plot)")
50
+ print("; ncl icon_plot.ncl 'iFile=" + dq + "iconOutput.nc" + dq + "' 'varName=" + dq + "T" + dq + "' 'vecVars=" + dq + "u-veloc v-veloc" + dq + "'")
51
+ print("; same for current atmo input")
52
+ print("; ncl icon_plot.ncl 'iFile=" + dq + "atm.nc" + dq + "' 'varName=" + dq + "T" + dq + "' 'vecVars=" + dq + "U V" + dq + "'")
53
+ print(";")
54
+ print("; Atmosphere input plotted on the 3rd height level")
55
+ print("; ncl icon_plot.ncl 'iFile=" + dq + "atm.nc" + dq + "' 'varName=" + dq + "T" + dq + "' 'atmLev=" + dq + "h" + dq + "' levIndex=2")
56
+ print("; Same but on pressure level")
57
+ print("; ncl icon_plot.ncl 'iFile=" + dq + "atm.nc" + dq + "' 'varName=" + dq + "T" + dq + "' 'atmLev=" + dq + "p" + dq + "' levIndex=2")
58
+ print("; Options can be combined execept showGrid=True with vector and overlay plots")
59
+ print(";---------------------------------------------------------------")
60
+ print(";")
61
+ print("; Required Parameter:")
62
+ print("; iFile : input file (based in ICON horizonal Grid or regular lonlat grid)")
63
+ print("; oFile : plot file wihtout extension (it set by the output type: oType)")
64
+ print("; varName : name of the variable to (contour) plot")
65
+ print("; vecVars : space separated string of the 2 vector components u and v to")
66
+ print("; draw a vector plot, array notation is also possible:")
67
+ print("; vecVars='" + dq + "u v" + dq + "' or vecVars='(/" + dq + "u" + dq + "," + dq + "v" + dq + "/)'")
68
+ print(";")
69
+ print("; Optional Parameter:")
70
+ print("; oType : output graphics format (ps, eps, png, default: eps)")
71
+ print("; resolution : resolution string whish is used for remapping the icon data")
72
+ print("; to regular grid (default: r90x45)")
73
+ print("; vecRefLength : reference vector length (default: 8.0)")
74
+ print("; vecColByLen : should vectors get coloured according to their lengths (default:False)")
75
+ print("; vecMinDist : minimal distance between vectors (default:0.017)")
76
+ print("; streamLine : display streamlines instead of vectors")
77
+ print("; timeStep : no of timestep (default:0)")
78
+ print("; levIndex : vertical level index (default:0)")
79
+ print("; isIcon : input is horiz. ICON style netcdf data (default:false), ")
80
+ print("; manually set this to prevent from checks")
81
+ print("; minVar/maxVar : set the lower/upper limit of the labelbar")
82
+ print("; mapLLC : (lon,lat) value array of the Lower Left Corner of the map")
83
+ print("; mapURC : (lon,lat) ------- || ------- Upper Right Corner of the map")
84
+ print("; use -180 to 180 for longitude !")
85
+ print("; secLC, secRC : start and and point of a vertical section (no default value)")
86
+ print("; section is plotted it secLC and secRC are present")
87
+ print("; showSecMap : display the location of the vertical section in an additional map (default:true)")
88
+ print("; centerLon : center longitute for satelite view (default:30.)")
89
+ print("; centerLat : center latitude for satelite view (default:20.)")
90
+ print("; satDist : satelite distance (default:20.0)")
91
+ print("; scaleFactor : optional scale factor")
92
+ print("; selMode : mode for level spacing of the plot:")
93
+ print("; halflog (uses half logarythmic levels,i.e. 1,2,5 per decade), ")
94
+ print("; manual (automatic linear spacing with usage of minVar and maxVar)")
95
+ print("; auto (default: let do ncl the spacing)")
96
+ print("; scaleLimit : Limits the number of decades for levels in selMode-halflog")
97
+ print("; minVar/maxVar : min/maximal Value to plot for selMode=manual or halflog")
98
+ print("; numLevs : set a number of labels for manual selMode only. NumCol=numLevs+2")
99
+ print("; (Not set directly, but used for computing the contour level spacing. default=10)")
100
+ print("; contLevs : set individual contour levels (not yet)")
101
+ print("; mapType : projection type (default: lonlat), other: ortho (not compatible with showGrid), NHps")
102
+ print("; and SHps (polar stereographic projections centered at the north and south pole respectively),")
103
+ print("; sat (satelite view, use option centerLat, centerLon and satDist)")
104
+ print("; mapLine : (logical) draws continent lines on the plot (foreground/transparent)")
105
+ print("; maskName : variable to mask with. maskName is expected NOT to have time dimension")
106
+ print("; 'maskName=" + dq + "none" + dq + "' is same as default (no mask variable)")
107
+ print("; maskFile : optional Filename of the mask variable maskName")
108
+ print("; it's only taken into account, if maskName is given")
109
+ print("; lonCo/latCo : default coordinate variables (default: clon/clat)")
110
+ print("; gridFile : use the given file for reading the coordintes (comming from lonCo and latCo)")
111
+ print("; lStrg : left string")
112
+ print("; rStrg : right string")
113
+ print("; tStrg : title string")
114
+ print("; bStrg : base string - default is prgr name and time stamp only")
115
+ print("; maxView : (logical) maximize plot area on paper (not for buildbot -> convert to png)")
116
+ print("; colormap : string for predefined colormaps of the plot (e.g. 'colormap=" + dq + "BlAqGrYeOrReVi200" + dq + "')")
117
+ print("; showGrid : display polygon lines with filled colors instead of contour plot")
118
+ print("; showNcd : display NDC Grid to find Normalized Device Coordinates on the plot")
119
+ print("; k2c : if True, perform Kelvin2Celsius shift (default:True)")
120
+ print(";")
121
+ print("; ATMOSPEHRE STUFF:")
122
+ print("; atmLev : chooses vertical plot levels for atmosphere input (h: height,p:pressure,m:modellevel,default:p)")
123
+ print(";---------------------------------------------------------------")
124
+ print("; altLibDir : Alternative directory for loading icon_plot_lib.ncl")
125
+ print("; cdo : Path to an alternative cdo version")
126
+ print(";---------------------------------------------------------------")
127
+ print("; Authors : Ralf Mueller (ralf.mueller@zmaw.de)")
128
+ print("; Stephan Lorenz (stephan.lorenz@zmaw.de)")
129
+ print("; VERSION : r8012 (2012-01-26)")
130
+ print(";---------------------------------------------------------------")
131
+ exit()
132
+ end if
133
+ ;- options handling + checking
134
+ wcStrt = systemfunc("date")
135
+
136
+ print("+++++ "+wcStrt)
137
+
138
+ Model = "Icon: explicit ocean test"
139
+
140
+ if(.not. isvar("iFile")) then
141
+ print("Input file is required! Use iFile option.")
142
+ print(ABORTMSG)
143
+ exit
144
+ else
145
+ if ( .not. isfilepresent(iFile) )
146
+ print("Could not read from input file: "+iFile+"!")
147
+ print(ABORTMSG)
148
+ exit
149
+ end if
150
+ end if
151
+ if(.not. isvar("iType")) iType = "oce" end if
152
+
153
+ if(.not. isvar("oType")) oType = "eps" end if
154
+ if(.not. isvar("oFile")) then
155
+ ext = get_file_suffix(iFile,0)
156
+ oFile = ext@fBase
157
+ end if
158
+ print("Outputfile '"+str_concat((/oFile,".",oType/))+"' will be created in "+systemfunc("dirname "+iFile))
159
+
160
+ if(.not. isvar("numLevs")) then
161
+ numLevs = NUMLEVS
162
+ else
163
+ if (numLevs .lt. 1) then
164
+ print("WARNING: numLevs must be >= 1")
165
+ print(ABORTMSG)
166
+ exit
167
+ end if
168
+ end if
169
+
170
+ if (.not. isvar("DEBUG")) DEBUG = False end if
171
+ if (.not. isvar("showGrid")) showGrid = False end if
172
+ if (.not. isvar("showNdc")) showNdc = False end if
173
+ if (.not. isvar("maxView")) maxView = False end if
174
+ if (.not. isvar("scaleLimit")) scaleLimit = 2 end if
175
+ if (.not. isvar("selMode")) selMode = "auto" end if
176
+ if (.not. isvar("plotMode")) plotMode = "scalar" end if
177
+ if (.not. isvar("timeStep")) timeStep = 0 end if
178
+ if (.not. isvar("levIndex")) levIndex = 0 end if
179
+ if (.not. isvar("scaleFactor")) scaleFactor = 1 end if
180
+ if (.not. isvar("colormap")) colormap = "BlueDarkRed18" end if
181
+ if (.not. isvar("k2c")) k2c = True end if
182
+ if (.not. isvar("isIcon")) isIcon = False end if
183
+
184
+ if (.not.isvar("mapType")) mapType = "lonlat" end if
185
+ if ( mapType .eq. "NHps" .and. .not.isvar("mapLLC")) mapLLC = (/-45., 45./) end if
186
+ if ( mapType .eq. "NHps" .and. .not.isvar("mapURC")) mapURC = (/135., 45./) end if
187
+ if ( mapType .eq. "SHps" .and. .not.isvar("mapLLC")) mapLLC = (/-45.,-45./) end if
188
+ if ( mapType .eq. "SHps" .and. .not.isvar("mapURC")) mapURC = (/135.,-45./) end if
189
+
190
+ if (.not.isvar("mapLLC")) mapLLC = (/-180.,-90./) end if
191
+ if (.not.isvar("mapURC")) mapURC = (/180.0,90.0/) end if
192
+ if (.not.isvar("centerLon")) centerLon = -30. end if
193
+ if (.not.isvar("centerLat")) centerLat = 20. end if
194
+ if (.not.isvar("satDist")) satDist = 20. end if
195
+ if (.not.isvar("mapLine")) mapLine = True end if
196
+ if (.not.isvar("resolution")) resolution = "r90x45" end if
197
+ if (.not.isvar("vecRefLength")) vecRefLength = 8.0 end if
198
+ if (.not.isvar("vecColByLen")) vecColByLen = False end if
199
+ if (.not.isvar("vecMinDist")) vecMinDist = 0.017 end if
200
+ if (.not.isvar("streamLine")) streamLine = False end if
201
+ if (.not.isvar("secPoints")) secPoints = 20 end if
202
+ ; default + optional coordinates
203
+ if (.not.isvar("lonCo")) lonCo = DEFAULTLON end if
204
+ if (.not.isvar("latCo")) latCo = DEFAULTLAT end if
205
+
206
+ if (.not.isvar("showSecMap")) showSecMap = True end if
207
+ ; ATMOSPEHRE SETUP ----------------------------------------------------------
208
+ if (.not.isvar("atmLev")) atmLev = "p" end if
209
+ if (.not.isvar("atmPLevs")) then
210
+ atmPLevSetup = (/10000,100000,2500/); unit: Pa
211
+ atmPLevs = ispan(atmPLevSetup(0),atmPLevSetup(1),atmPLevSetup(2))*1.0
212
+ end if
213
+ if (.not.isvar("atmHLevs")) then
214
+ atmHLevSetup = (/0,100000,2000/); unit: m
215
+ atmHLevs = ispan(atmHLevSetup(0),atmHLevSetup(1),atmHLevSetup(2))*1.0
216
+ end if
217
+ ; CDO settings --------------------------------------------------------------
218
+ if (.not.isvar("cdo")) cdo = "cdo" end if
219
+ setCDO(cdo)
220
+ ;----------------------------------------------------------------------------
221
+
222
+ ; MASK HANDLING -------------------------------------------------------------
223
+ if (.not.isvar("maskName"))
224
+ useMask = False
225
+ else
226
+ if ( .not.isstring(maskName)) then
227
+ print("Parameter 'maskName' has to be a string!")
228
+ exit
229
+ else
230
+ useMask = True
231
+ if (.not.isvar("maskFile"))
232
+ if (maskName.eq."none") then
233
+ useMask = False
234
+ else
235
+ if (DEBUG) then
236
+ print("Use internal mask variable " +maskName)
237
+ end if
238
+ end if
239
+ else
240
+ if (DEBUG) then
241
+ print("Use external mask file " + maskFile)
242
+ end if
243
+ end if
244
+ end if
245
+ end if
246
+ ;----------------------------------------------------------------------------
247
+
248
+
249
+ ; DETERMINE INPUT TYPE ------------------------------------------------------
250
+ if (isvar("varName")) then
251
+ ivarname = varName
252
+ else
253
+ if (isvar("vecVars")) then
254
+ size = dimsizes(vecVars)
255
+ if (1.lt.size) then
256
+ ivarname = vecVars(0)
257
+ else
258
+ if (isstring(vecVars)) then
259
+ vecs = str_split(vecVars," ")
260
+ ivarname = vecs(0)
261
+ else
262
+ print("Cannot determinte input variable! Please provide varName or vecVars.")
263
+ exit
264
+ end if
265
+ end if
266
+ delete(size)
267
+ else
268
+ print("Cannot determinte input variable! Please provide varName or vecVars.")
269
+ exit
270
+ end if
271
+ end if
272
+ if (getVarLevelType(iFile,ivarname) .eq. "hybrid") then ;atm input
273
+ iType = "atm"; oce otherwise
274
+ if (atmLev .ne. "m" ) then
275
+ atmPreProcFilename = preProc4Atm(iFile,atmLev,atmPLevs,atmHLevs,DEBUG)
276
+ iFile = atmPreProcFilename
277
+ end if
278
+ end if
279
+ ; DETERMINE HORIZONTAL GRID -------------------------------------------------
280
+ horizonalGridType = getHorizGridType(iFile,ivarname,isIcon)
281
+ ;----------------------------------------------------------------------------
282
+
283
+ ; DETERMINE THE PLOTMODE ----------------------------------------------------
284
+ if (isvar("vecVars")) then
285
+ ; expectes is a string or an array of size 2: "u-veloc v-veloc" or (/"u-veloc","v-veloc"/)
286
+ if (1 .eq. dimsizes(vecVars)) then
287
+ if (isstring(vecVars)) then
288
+ vecVars_ = str_split(vecVars," ")
289
+ delete(vecVars)
290
+ vecVars = vecVars_
291
+ else
292
+ print("Please provide a valid description of vector variables")
293
+ exit
294
+ end if
295
+ end if
296
+ if (plotMode .ne. "scatter") then
297
+ plotMode = "vector"
298
+ if (isvar("varName")) plotMode = "overlay" end if
299
+ end if
300
+ else
301
+ if (isvar("scatVars")) then
302
+ plotMode = "scatter"
303
+ else
304
+ plotMode = "scalar"
305
+ end if
306
+ end if
307
+
308
+ if ( (isvar("secLC").or.isvar("secRC")).ne.(isvar("secLC").and.isvar("secRC"))) then
309
+ print("Please provide secLC AND secRC for generatin a section plot!")
310
+ exit
311
+ end if
312
+ if (isvar("secLC").and.isvar("secRC")) plotMode = "section" end if
313
+ if (isvar("hoff")) plotMode = "hoffmueller" end if
314
+
315
+ if (plotMode.eq."vector" .or. plotMode.eq."overlay" .or. plotMode.eq."section" .or. plotMode .eq. "hoffmueller") then
316
+ if (horizonalGridType .ne. "unstructured") then ; regular grid expected, i.e. remappgin is NOT required
317
+ rFile = addfile(iFile+".nc","r")
318
+ else
319
+ ; performe some remapping to a regular grid because ncl cannot draw vector
320
+ ; from unstructured grids
321
+ ; TODO addVars=(/ "PS","PHIS"/)
322
+ remapFilename = setRemapFilename(iFile,iType,atmLev)
323
+ print("remapFilename:"+remapFilename)
324
+ if (.not. checkRemappedFile(iFile,remapFilename,ivarname,iType,atmLev,atmPLevs,atmHLevs) ) then
325
+ addVars=(/""/)
326
+ print("PERFORM remapnn again!")
327
+ remapForVecPlot(iFile,remapFilename,resolution,useMask,plotMode,DEBUG,addVars)
328
+ end if
329
+ rFile = addfile( remapFilename+".nc", "r" )
330
+ end if
331
+ if (plotMode .eq. "hoffmueller") then ; perform zonmean
332
+ zonmeanFilename = setZonmeanFilename(remapFilename,ivarname,atmLev)
333
+ zonmean4HoffmuellerPlot(remapFilename,ivarname,zonmeanFilename)
334
+ end if
335
+ end if
336
+ File = addfile( iFile+".nc", "r" )
337
+
338
+ if (DEBUG) printVarNames(File) end if
339
+
340
+ ;Read mask variable
341
+ if( useMask ) then
342
+ mFile = File
343
+ if (isvar("maskFile")) then
344
+ maskVar = getMaskVar(maskName,File,True,maskFile,timeStep,levIndex,plotMode,horizonalGridType)
345
+ else
346
+ if (plotMode.eq."vector" .or. plotMode.eq."section") then
347
+ maskVar = getMaskVar(maskName,rFile,False,"",timeStep,levIndex,plotMode,horizonalGridType)
348
+ else
349
+ maskVar = getMaskVar(maskName,File,False,"",timeStep,levIndex,plotMode,horizonalGridType)
350
+ end if
351
+ end if
352
+ end if
353
+
354
+ if (plotMode.eq."vector") then
355
+ print("Plot vector variables: " + vecVars)
356
+ else
357
+ if (plotMode.eq."overlay") then
358
+ print("Plot vector variables: " + vecVars)
359
+ print("Plot variable: " + varName)
360
+ end if
361
+ if (plotMode.eq."section") then
362
+ print("Plot variable: " + varName)
363
+ end if
364
+ end if
365
+ ;---------------------------------------------------------------
366
+ if (DEBUG) then
367
+ print("iFile = "+iFile)
368
+ print("oFile = "+oFile)
369
+ print("Graphics format is " +oType)
370
+ print("plotMode = "+plotMode)
371
+
372
+ if (plotMode.eq."scalar" .or. plotMode.eq."section") then
373
+ print("varName = "+varName)
374
+ else
375
+ print("vecVars = "+vecVars)
376
+ if (plotMode.eq."overlay") then print("varName = "+varName) end if
377
+ end if
378
+
379
+ print("timeStep = "+timeStep)
380
+ print("mapLLC(lon) = "+mapLLC(0))
381
+ print("mapLLC(lat) = "+mapLLC(1))
382
+ print("mapURC(lon) = "+mapURC(0))
383
+ print("mapURC(lat) = "+mapURC(1))
384
+ if (useMask) then
385
+ print("maskName = "+maskName)
386
+ end if
387
+ print("#==== END OF DEBUG OUTPUT =====================================")
388
+ end if
389
+ ;---------------------------------------------------------------
390
+
391
+
392
+ ; Reading data variables =====================================================
393
+ if (plotMode.eq."scalar" .or. plotMode.eq."overlay") then ; scalar mode ======
394
+
395
+ printVar(varName, File)
396
+
397
+ var = selField(varName,File,timeStep,levIndex,horizonalGridType)
398
+
399
+ if (horizonalGridType .eq. "unstructured") then
400
+ if (isvar("gridFile")) then
401
+ x = getCoordinateFromFile(lonCo,gridFile)
402
+ y = getCoordinateFromFile(latCo,gridFile)
403
+ if (showGrid) then
404
+ bounds = getBoundsFromFile(lonCo,latCo,gridFile)
405
+ end if
406
+ else
407
+ lonlatSizes = getCoordSizes(var,File)
408
+ x = new(lonlatSizes(0),double)
409
+ y = new(lonlatSizes(1),double)
410
+ getLonLats(var,File,x,y)
411
+ if (showGrid) then
412
+ bounds = getBoundsOfCoordinates(var,File)
413
+ end if
414
+ end if
415
+ end if
416
+
417
+ scaleVar(var,scaleFactor)
418
+
419
+ ; set selMode automatically
420
+ if (isvar("minVar") .and. isvar("maxVar")) then
421
+ if (selMode .eq. "auto") then
422
+ selMode = "manual"
423
+ end if
424
+ end if
425
+ ; set minVar_maxVar for plotting
426
+ if(.not. isvar("minVar")) minVar = min(var) end if
427
+ if(.not. isvar("maxVar")) maxVar = max(var) end if
428
+ checkMinMaxVar(minVar,maxVar)
429
+
430
+ if ( useMask ) then
431
+ ; set variable var to missing, where var is not equal mvalue (3rd
432
+ ; parameter)
433
+ var = mask(var,maskVar,1)
434
+ ;slm = maskVar - 0.5
435
+ ;var = mask ( var, slm, 0.5)
436
+ end if
437
+ end if
438
+ if (plotMode.eq."vector" .or. plotMode.eq."overlay") then; vector mode =======
439
+ uvarname = vecVars(0)
440
+ vvarname = vecVars(1)
441
+
442
+ if (has_var(rFile,uvarname) .and. has_var(rFile,vvarname)) then
443
+ checkDimsOfVars(uvarname,vvarname,rFile)
444
+ else
445
+ print("Remapped file does not have variables "+uvarname+" or "+vvarname+"!")
446
+ exit
447
+ end if
448
+
449
+ uvar = selRegularField(uvarname,rFile,timeStep,levIndex)
450
+ vvar = selRegularField(vvarname,rFile,timeStep,levIndex)
451
+
452
+ scaleVar(uvar,scaleFactor)
453
+ scaleVar(vvar,scaleFactor)
454
+
455
+ if ( useMask ) then
456
+ uvar = mask(uvar,maskVar,1)
457
+ vvar = mask(vvar,maskVar,1)
458
+ end if
459
+
460
+ velocity = sqrt(uvar*uvar + vvar*vvar)
461
+ ; set minVar/maxVar for plotting
462
+ if(.not. isvar("minVar")) minVar = min(velocity) end if
463
+ if(.not. isvar("maxVar")) maxVar = max(velocity) end if
464
+ checkMinMaxVar(minVar,maxVar)
465
+ end if
466
+ if (plotMode.eq."scatter") then; scatter plot ================================
467
+ xvarname = vecVars(0)
468
+ yvarname = vecVars(1)
469
+ xvar = selField(xvarname,File,timeStep,levIndex,horizonalGridType)
470
+ yvar = selField(yvarname,File,timeStep,levIndex,horizonalGridType)
471
+ scaleVar(xvar,scaleFactor)
472
+ scaleVar(yvar,scaleFactor)
473
+ if ( useMask ) then
474
+ xvar = mask(xvar,maskVar,1)
475
+ yvar = mask(yvar,maskVar,1)
476
+ end if
477
+ end if
478
+ if (plotMode.eq."section") then; section mode ================================
479
+ print(rFile)
480
+ var = selRegularVar(varName,rFile,timeStep)
481
+ if(.not. isvar("minVar")) minVar = min(var) end if
482
+ if(.not. isvar("maxVar")) maxVar = max(var) end if
483
+ checkMinMaxVar(minVar,maxVar)
484
+ ; masking before computing the cross section
485
+ if ( useMask ) then
486
+ ; set variable var to missing, where var is not equal mvalue (3rd
487
+ ; parameter)
488
+ var = mask(var,maskVar,1)
489
+ end if
490
+ end if ; Reading data variables =============================================
491
+ if (plotMode .eq. "hoffmueller") then ; create hoffmuelle diagram
492
+ ; select the whole time series
493
+ ; and plot it with
494
+ ; plot = gsn_csm_lat_time(wks, shov(0,{-80:80},:), res)
495
+ end if
496
+ if (iType .eq. "atm" .and. ivarname .eq. "T" .and. k2c) var = var - 273.15 end if ;atmosphere used to write out Kelvin
497
+
498
+ ;---------------------------------------------------------------
499
+ ; make the plot
500
+ ;---------------------------------------------------------------
501
+ ; preparations
502
+ wks = gsn_open_wks(oType,oFile)
503
+
504
+ gsn_define_colormap(wks,colormap)
505
+
506
+ if (showNdc)
507
+ drawNDCGrid(wks)
508
+ end if
509
+
510
+ ResC = True
511
+
512
+ setDefaultResource(ResC,True)
513
+
514
+ if (maxView) ResC@gsnMaximize = True end if
515
+
516
+ if (useMask) setMaskColor(wks,ResC) end if
517
+
518
+
519
+
520
+ if (getHorizGridType(iFile,ivarname,isIcon) .eq. "unstructured") then
521
+ if (plotMode.eq."scalar" .or. plotMode.eq."overlay")
522
+ setCoordinates(ResC,x,y)
523
+ ;setBounds(ResC,File,x,y,DEBUG)
524
+ end if
525
+ end if
526
+
527
+ if (plotMode.eq."vector") then
528
+ setAutomaticPlotCaptions(ResC,plotMode,vecVars(0),File,iFile,timeStep,levIndex,iType,atmLev,k2c)
529
+ else
530
+ setAutomaticPlotCaptions(ResC,plotMode,varName,File,iFile,timeStep,levIndex,iType,atmLev,k2c)
531
+ end if
532
+
533
+ if (plotMode.eq."section") then
534
+ if ( ismissing(getVertDim(File,var)) ) then
535
+ print("Cannot plot vertical section of a 2D variable: "+varName)
536
+ exit
537
+ end if
538
+ trans = setSection(secLC,secRC,secPoints,var)
539
+ vertdim = getVertDim(File,var)
540
+ trans!0 = vertdim
541
+ trans&$vertdim$ = var&$vertdim$
542
+ end if
543
+
544
+ setAutomaticBaseString(wks,plotMode)
545
+
546
+ setLevels(selMode,ResC,minVar,maxVar,scaleLimit,numLevs,DEBUG)
547
+
548
+ setMapType(ResC,mapType,centerLon,centerLat,satDist)
549
+
550
+ selMapCut(ResC,mapLLC,mapURC)
551
+
552
+ setMapVisibility(ResC,mapLine)
553
+
554
+ if (DEBUG) showMapInfo(ResC,mapType,mapLine) end if
555
+
556
+ ; MAIN PLOT CALLS ===========================================================
557
+ if (plotMode .eq. "vector") then ; vector plot ==============================
558
+ if (showGrid) then
559
+ print("#= WARNING =============================================")
560
+ print("Display Vectors and the underlying grid is not usefull, ")
561
+ print("because original data is interpolated to a regular grid for vector representation.")
562
+ print(ABORTMSG)
563
+ exit
564
+ else
565
+ setDefaultVectorPlot(ResC,5.0,vecRefLength,"CurlyVector",vecMinDist)
566
+
567
+ vc = plotVecOrStream(vecColByLen,streamLine,uvar,vvar,velocity,ResC,wks,True)
568
+ end if
569
+ end if
570
+ if (plotMode.eq."overlay") then
571
+ ;reset the second resource
572
+ ResC2 = ResC
573
+ setDefaultOverlayResource(ResC2)
574
+ setPlotCaptions(ResC2,"","","","")
575
+ selMapCut(ResC2,mapLLC,mapURC)
576
+ setDefaultVectorPlot(ResC2,5.0,vecRefLength,"CurlyVector",vecMinDist)
577
+
578
+ ResC@gsnDraw = False
579
+ ResC@gsnFrame = False
580
+ vc = plotVecOrStream(vecColByLen,streamLine,uvar,vvar,velocity,ResC2,wks,False)
581
+
582
+ plot = gsn_csm_contour_map(wks,var,ResC)
583
+ if (showGrid) then
584
+ print("plotting GRID in overlay mode is not supported")
585
+ exit
586
+ end if
587
+
588
+ overlay(plot,vc)
589
+ draw(plot)
590
+ end if
591
+ if (plotMode.eq."scalar") then
592
+ if (DEBUG .and. horizonalGridType.eq."unstructured") print("Gridtype is "+getGridType(var)) end if
593
+ plot = gsn_csm_contour_map(wks,var,ResC)
594
+
595
+ if (showGrid) then
596
+ if ( horizonalGridType .ne. "unstructured") then
597
+ print("#=====================================================================")
598
+ print("Grid representation is only implemented for the unstructured ICON grid")
599
+ exit
600
+ end if
601
+ plotGrid(wks,plot,var,x,bounds,File,ResC,DEBUG)
602
+ end if
603
+ end if
604
+ if (plotMode.eq."scatter") then
605
+ plot = gsn_csm_xy(wks,xvar,yvar,ResC)
606
+ end if
607
+ if (plotMode.eq."section") then
608
+
609
+ if (showSecMap) then
610
+ plot = new(2,graphic)
611
+ else
612
+ plot = new(1,graphic)
613
+ end if
614
+ points = ispan(0,secPoints-1,1)*1.0
615
+
616
+ res = setDefaultSectionResource(points,secPoints,secLC,secRC)
617
+ setAutomaticPlotCaptions(res,plotMode,varName,File,iFile,timeStep,levIndex,iType,atmLev,k2c)
618
+ setLevels(selMode,res,minVar,maxVar,scaleLimit,numLevs,DEBUG)
619
+ setSectionVertLabel(res,iType,atmLev)
620
+
621
+ if (showSecMap) then
622
+ shift4SecMap(res)
623
+ end if
624
+
625
+ plot(0) = gsn_csm_contour(wks,trans,res); create plot
626
+ draw(plot(0))
627
+
628
+ if (showSecMap) then
629
+ ; map with section polygon
630
+ mres = True
631
+ mres@gsnFrame = False; don't turn page yet
632
+ mres@gsnDraw = False; don't draw yet
633
+ mres@vpWidthF = 0.8; set width of plot
634
+ mres@vpHeightF = 0.3; set height of plot
635
+ mres@vpXF = 0.1
636
+ mres@vpYF = 0.4
637
+ plot(1) = gsn_csm_map_ce(wks,mres)
638
+ pres = True; polyline mods desired
639
+ pres@gsnFrame = False; don't turn page yet
640
+ pres@gsnDraw = False; don't draw yet
641
+ pres@gsLineColor = "black"; color of lines
642
+ pres@gsLineThicknessF = 2.0; line thickness
643
+ dummy = gsn_add_polyline(wks,plot(1),(/ secLC(0),secRC(0) /),(/ secLC(1),secRC(1) /),pres)
644
+
645
+ draw(plot(1))
646
+ end if
647
+ end if
648
+
649
+ if (DEBUG) print(ResC) end if
650
+
651
+ frame(wks)
652
+ ;
653
+ ; vim:list