; ncl_talk: 31 July 2017: Andrew Kren ; I am looping through forecast hours in a TC track file to examine track error. ; The issue is that multiple lines have identical forecast hours on each line so ; that it is an issue with my code that I was reading the same lat/lons and ; treating them the same as if they were independent forecast hours. ; Attached is a text file of the track file and my ncl script. ; Is there a way to use get_unique_values to get the indices from the ; unique values so that I am only saving those values and not duplicating? ; ;--- file snippet------------ ;atcfunix.gfs.2006081900:AL, 01, 2006081900, 03, PRCT, 000, 141N, 204W, 26, 1005, XX, 34, NEQ, 0000, 0000, 0000, 0000, 1009, 157, 61 ;atcfunix.gfs.2006081900:AL, 01, 2006081900, 03, PRCT, 006, 146N, 222W, 25, 1004, XX, 34, NEQ, 0000, 0000, 0000, 0000, 1008, 225, 160 ;---------------------------- diri = "./" fili = "AL01.txt" pthi = diri+fili dstr = asciiread(pthi, -1, "string") ; read as type 'string' dlim = ", " nfld = str_fields_count(dstr(0),dlim) ; nfld=20 YMDH = str_get_field(dstr, 3, dlim) ; YyyyMmDdHh (YMDH) LAT = str_get_field(dstr, 7, dlim) LON = str_get_field(dstr, 8, dlim) N = dimsizes(LAT) ; total # values/lines/rows in file print("N="+N) print("-----") ;---Create a 'KEY' ; combine strings KEY = YMDH + LAT + LON ; 2006081900141N204W ; 012345678901234567 ; col #s; 0-based nuKEY = count_unique_values(KEY) print("nuKEY="+nuKEY) print("-----") uKEY = get_unique_values(KEY) ; unique KEYs print("uKEY="+uKEY) print("-----") ymdh = toint(str_get_cols(uKEY, 0, 9)) ; 2006081900 yyyy = toint(str_get_cols(uKEY, 0, 3)) ; 2006 mm = toint(str_get_cols(uKEY, 4, 5)) ; 08-> 8 dd = toint(str_get_cols(uKEY, 6, 7)) ; 19 hh = toint(str_get_cols(uKEY, 8, 9)) ; 00 -> 0 lat = tofloat(str_get_cols(uKEY,10,12))*0.1 lat = where(str_get_cols(uKEY,13,13).eq."S", -lat, lat) lon = tofloat(str_get_cols(uKEY,14,16))*0.1 lon = where(str_get_cols(uKEY,17,17).eq."W", -lon, lon) print(ymdh+" "+lat+" "+lon) print("-----") ; Alternative; indices corresponding to the unique values i = ind(KEY(0:N-2).ne.KEY(1:N-1)) ; indices where successive values differ ni = dimsizes(i) if (ismissing(i(0))) then print("All values the same") ni = 1 i = 0 else if (KEY(N-2).ne.KEY(N-1)) then ; last value special handling NI = ni+1 I = new(NI, integer, "No_FillValue") I(0:ni-1) = i ; copy previous 'i' I(ni) = N-1 ; add last index ni = NI i := I(0:NI-1) end if end if print("ni="+ni) print("-----") print("-----") print("i="+i+" "+KEY(i)) print("-----") print("-----") print(dstr(i)) ; print lines/rows of unique values