Subversion Repositories lagranto.ocean

Rev

Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
3 michaesp 1
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
2
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"
3
load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"
4
;-------------------------------------------------------------------------------------;
5
;-------------------------------------------------------------------------------------;
6
 
7
 
8
;-------------------------------------------------------------------------------------;
9
; FUNCTION TO READ IN TRAJECTORIES
10
;-------------------------------------------------------------------------------------;
11
undef("read_traj")
12
function read_traj (lslfile:string, flag:string, nshift:integer)
13
;-------------------------------------------------------------------------------------;
14
; 	Input : Lagranto ECMWF lsl output, old or new Lagranto ?
15
; 	Output: 4d Trajectorie array with Traj(number of traj, timestep, fields)
16
;-------------------------------------------------------------------------------------;
17
local nhead, head, delim, data, n, ifirst, ifinal, timestp, ntra, traj, vars, flag, nshift
18
;-------------------------------------------------------------------------------------;
19
begin
20
;---------- Read file ----------------------------------------------------------------;
21
print(" ")
22
if (flag .eq. "new") then
23
print("Assuming Lagranto 2.0 header")
24
end if
25
if (flag .eq. "old") then
26
print("Assuming old Lagranto header")
27
end if
28
if (flag .eq. "oldlm") then
29
print("Assuming old Lagranto LM header")
30
end if
31
 
32
; Delimiting character
33
delim	= " "
34
 
35
; Number of header lines
36
nhead   = 4
37
 
38
; Read header lines
39
head    = systemfunc("head -n"+nhead+" "+ lslfile)
40
 
41
; Number of columns
42
ncol    = str_fields_count(head(2),delim)
43
 
44
; Read data in as float
45
data	= asciiread(lslfile,-1,"float")
46
 
47
; Number of entries in data
48
n       = dimsizes(data)
49
 
50
; First data element
51
if (flag .eq. "new") then
52
ifirst  = 3 + nshift
53
end if
54
if (flag .eq. "oldlm") then
55
ifirst  = 4 + nshift
56
end if
57
if (flag .eq. "old") then
58
ifirst  = 5 + nshift
59
end if
60
 
61
; Last data element
62
ifinal  = n-1
63
 
64
; Period
65
period  = data(ifinal-ncol+1)  - data(ifirst)
66
 
67
; Time step of trajectories
68
timestp = data(ifirst+ncol) - data(ifirst)
69
 
70
; Number of times
71
ntim    = floattoint( period/timestp + 1 )
72
 
73
; Number of trajectories
74
ntra    = floattoint( (n-ifirst) / (ntim * ncol ) )
75
 
76
; 3d trajectory array
77
traj    = onedtond(data(ifirst:ifinal),(/ntra,ntim,ncol/))
78
 
79
; Field names (columns)
80
vars    = str_split(head(2),delim)
81
 
82
;-------------- Add meta information 
83
if (flag .eq. "new") then
84
; Add some attributes to the variable
85
traj@HOUR        = stringtoint( str_get_cols(head(0),24,25) )
86
traj@DAY         = stringtoint( str_get_cols(head(0),21,22) )
87
traj@MONTH       = stringtoint( str_get_cols(head(0),19,20) )
88
traj@YEAR        = stringtoint( str_get_cols(head(0),15,18) )
89
traj@FIELD_NAMES = vars
90
traj@TIMEPERIOD  = period
91
traj@TIMESTEP    = timestp
92
traj@MODEL       = "LAGRANTO 2.0"
93
end if
94
 
95
if (flag .eq. "old") then
96
traj@HOUR        = stringtoint( str_get_cols(head(0),22,23) )
97
traj@DAY         = stringtoint( str_get_cols(head(0),19,20) )
98
traj@MONTH       = stringtoint( str_get_cols(head(0),17,18) )
99
traj@YEAR        = stringtoint( str_get_cols(head(0),13,16) )
100
traj@FIELD_NAMES = vars
101
traj@FIELD_NAMES = vars
102
traj@TIMEPERIOD  = period
103
traj@TIMESTEP    = timestp
104
traj@MODEL       = "Lagranto"
105
end if
106
 
107
; Set names of dimensions and assign values
108
traj!0           = "TRA"
109
traj!1           = "TIME"
110
traj!2           = "FIELD"
111
traj&TIME        = fspan(0,period,ntim)
112
 
113
; print info
114
printVarSummary(traj)
115
 
116
return(traj)
117
print(" ")
118
 
119
;---- Clean
120
delete(traj)
121
delete(vars)
122
delete(data)
123
 
124
;---- end
125
end
126
;-------------------------------------------------------------------------------------;
127
;-------------------------------------------------------------------------------------;
128
 
129
 
130
;-------------------------------------------------------------------------------------;
131
; START OF NCL SCRIPT
132
;-------------------------------------------------------------------------------------;
133
 
134
system("\rm ._*")
135
 
136
 
137
; --------- Name of trajectory file --------------------------------------------------;
138
filename="LSL20040108_00"
139
 
140
; --- read trajectories
141
traj = read_traj(filename,"new",0)
142
 
143
; -- get infos
144
dims = dimsizes(traj)
145
ntra = dims(0)
146
ntim = dims(1)
147
fld  = dims(2)
148
 
149
; set field to plot
150
cnIndex = 3
151
 
152
; set the contour range
153
cnLev   = fspan(900,1210,31)
154
 
155
; --- create the plot
156
wks  = gsn_open_wks("eps","test.") 
157
gsn_define_colormap(wks,"MPL_YlGnBu")
158
 
159
; --- the map
160
res                        = True  
161
res@gsnDraw    			   = False                         
162
res@gsnFrame   			   = False                        
163
 
164
res@mpLandFillColor        = "gray50" 
165
res@mpDataBaseVersion      = "MediumRes"  
166
res@mpGreatCircleLinesOn   = True 
167
 
168
res@mpMinLonF              = -120
169
res@mpMaxLonF              =  -50
170
res@mpMinLatF			   =   10
171
res@mpMaxLatF              =   80
172
res@mpCenterLonF           =    0     
173
 
174
map 		= gsn_csm_map_ce(wks,res)  
175
 
176
; --- plot starting region
177
 
178
gres                 = True
179
gres@gsLineColor     = "black"
180
gres@gsLineDashPattern = 0
181
gres@gsLineThicknessF  = 1.
182
gres@tfPolyDrawOrder = "PreDraw"
183
gres@gsMarkerColor = "red"
184
gres@gsMarkerIndex = 15
185
 
186
la = (/ 30,  35,  35,  30,  30/)
187
lo = (/-75, -75, -70, -70, -75/)
188
 
189
;dum0 = gsn_add_polyline(wks,map,lo,la,gres)
190
 dum0 = gsn_add_polymarker(wks,map,-72.5,35,gres)    
191
 
192
; --- the trajectories
193
pres		  	 		   = True                         
194
pres@gsLineThicknessF      = 0.25 
195
 
196
 
197
do i = 0,ntra-1
198
if (traj(i,0,cnIndex).gt.1000 .and. traj(i,0,cnIndex).lt.1100  ) then
199
 
200
  x = traj(i,0:(ntim-1),1)    ; Longitudes for trajectory i
201
  y = traj(i,0:(ntim-1),2)    ; Latitudes for trajectory i
202
 
203
 do t = 0,ntim-2
204
 
205
	pres@gsLineColor = get_color_index("MPL_YlGnBu",cnLev,traj(i,t,cnIndex))  
206
    gsn_polyline  (wks,map,(/x(t),x(t+1)/),(/y(t),y(t+1)/),pres)  
207
 
208
end do
209
end if     
210
 
211
end do  
212
 
213
; --- Draw labelbar
214
cnLabels                 	  = flt2string(cnLev)        
215
cmap 						  = read_colormap_file("MPL_YlGnBu")
216
 
217
csizes = dimsizes(cmap)
218
nboxes = dimsizes(cnLev)+1       	  ; # of labelbar boxes
219
clen   = csizes(0)                    ; # of colors in color map
220
stride = ((clen-1) - 2) / nboxes      ; Start at color index 2 and end
221
                                      ; near color index clen-1.
222
 
223
fill_colors 				  = ispan(2,clen-1,stride)
224
 
225
lres                          = True
226
lres@lbTitleString            = "[m]"           
227
lres@lbTitleFontHeightF       = 0.015
228
lres@vpWidthF                 = 0.60                    
229
lres@vpHeightF                = 0.10                    
230
lres@lbPerimOn                = False                   
231
lres@lbOrientation            = "Horizontal"
232
 
233
lres@lbFillColors             = fill_colors             
234
lres@lbMonoFillPattern        = True    
235
lres@lbLabelFontHeightF       = 0.015                   
236
lres@lbLabelAutoStride        = True                   
237
 
238
lbid = gsn_create_labelbar(wks,nboxes,cnLabels,lres)
239
 
240
amres = True
241
amres@amZone           = 2
242
amres@amParallelPosF   = 0.5            ; Center labelbar.
243
amres@amOrthogonalPosF = 0.1            ; Move down, away from plot
244
 
245
annoid = gsn_add_annotation(map,lbid,amres)
246
 
247
 
248
 
249
; ---- create the plot
250
draw(map)
251
 
252
frame(wks) 
253