; ; This script reads all the "string" variables off a shapefile ; and searches each variable for a list of desired city names. ; ;---Open shapefile we want to examine shp_name = "TLS_adm2.shp" a = addfile(shp_name,"r") ;---Get list of variable names on the shapefile vnames = getfilevarnames(a) nvars = dimsizes(vnames) ;---Creat list of cities that we want to search for. ;desired_city_names = (/ "Cristo Rei", "Metinaro", "Vera Cruz", "Nain Feto", "Dom Aleixo"/) ; I recommend breaking up the two names into individual ones, just to see if maybe the ; spelling is slightly different. desired_city_names = (/ "Cristo", "Rei", "Metinaro", "Vera","Cruz", "Nain", "Feto", "Dom", "Aleixo"/) ncities = dimsizes(desired_city_names) ;---Create a logical array to keep track of which cities we found. found_city_name = new(ncities,logical) found_city_name = False ; ; Loop through each variable on the shapefile. If it's a string ; variable, then read it in and use "str_match" to see if the ; desired city names are in it. ; do nv=0,nvars-1 vtype = getfilevartypes(a,vnames(nv)) ; Get the type ("double", "string", etc) if(vtype.eq."string") then names := a->$vnames(nv)$ ; Read all the values of this particular variable do nc=0,ncities-1 idx := str_match_ind(names,desired_city_names(nc)) if(.not.any(ismissing(idx))) then print("======================================================================") print("Found one or more matches for '" + desired_city_names(nc) + \ "' in variable " + vnames(nv) + ":") print(" '" + names(idx) + "'") found_city_name(nc) = True end if end do end if end do print("======================================================================") print(desired_city_names + " found? " + found_city_name) print("======================================================================")