;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ; ; ; Script to read in synop data and put into the format required by MET tools ; ; ; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl" load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl" load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl" begin ;constants year = "2006" month = "06" day = "01" dtemp = new(1,"string") pressure = dtemp message_type = "ADPSFC" testfile = "/gpfs/env/nhm06sfu/June06/01/siuk21d_0300P.DATA" st_file = "/gpfs/env/nhm06sfu/WRFtry2/python_scripts/uk_stations.txt" ;find time in file time = str_split(testfile,"_") hr = str_split_by_length(time(1),2) hour = hr(0) full_time = year + month + day + "_" + hour + "0000" ;open station codes full_list = asciiread(st_file,-1,"string") print(full_list) st_id_all = str_get_field(full_list,1,",") lat_all = str_get_field(full_list,3,",") lon_all = str_get_field(full_list,4,",") ; read in observational file datafile = asciiread(testfile,-1,"string") print(datafile) length = dimsizes(datafile) temp_long_string = new(length,"string") dtemp_long_string = new(length,"string") wdir_long_string = new(length,"string") wspd_long_string = new(length,"string") pres_long_string = new(length,"string") test = datafile(0) do i = 0, length-1 data_split = str_split(datafile(i)," ") st_id = data_split(0) find_id = str_match(full_list,st_id) lat = str_get_field(find_id,3,",") lon = str_get_field(find_id,4,",") ;extract temperatures do j = 1, dimsizes(data_split)-1 tmp_test = str_index_of_substr(data_split(j),"1",1) if (.not.ismissing(tmp_test)) then if tmp_test.eq.0.and.j.ne.1 then tmp_h = data_split(j) tmpsplit = str_split_by_length(tmp_h,(/1,1,3/)) tmp_fl = stringtofloat(tmpsplit(2)) if tmpsplit(1).eq.1 then tmp_st = 273.15 - tmp_fl/10 else tmp_st = tmp_fl/10 + 273.15 end if temp = flt2string(tmp_st) ; print(temp) end if end if dtmp_test = str_index_of_substr(data_split(j),"2",0) if (.not.ismissing(dtmp_test(0))) then if dtmp_test(0).eq.0.and.j.ne.1 then if (ismissing(dtemp)) then dtmp_h = data_split(j) dtmpsplit = str_split_by_length(dtmp_h,(/1,1,3/)) dtmp_fl = stringtofloat(dtmpsplit(2)) if dtmpsplit(1).eq.1 then dtmp_st = 273.15 - dtmp_fl/10 else dtmp_st = dtmp_fl/10 + 273.15 end if dtemp = flt2string(dtmp_st) ; print(dtemp) end if end if end if delete(dtmp_test) delete(tmp_test) ;extract pressure pres_test = str_index_of_substr(data_split(j),"4",0) print(pres_test) if (.not.ismissing(pres_test)) then if pres_test(0).eq.0.and.j.ne.1 then if (ismissing(pressure)) then pres = data_split(j) pres_split = str_split_by_length(pres,(/1,4/)) size_p = str_split_by_length(pres_split(1),1) pres_fl = stringtofloat(pres_split(1)) if size_p(0).eq.9 then pres_st = pres_fl/10 else pres_st = 1000 + pres_fl/10 end if pressure = flt2string(pres_st) ; print(pressure) end if end if end if delete(pres_test) end do ;extract wind speed/direction wnd_test = data_split(2) wsplit = str_split_by_length(wnd_test,(/1,2,2/)) wdir = wsplit(1) + "0" wspd_fl = stringtofloat(wsplit(2)) wspd_ms = wspd_fl*0.515 wspd = flt2string(wspd_ms) ;output into files c = " " temp_long_string(i) = message_type + c + st_id + c + full_time + c + lat + c + lon + c + "-9999" + c + "011" + c + "-9999" + c + "-9999" + c + temp pres_long_string(i) = message_type + c + st_id + c + full_time + c + lat + c + lon + c + "-9999" + c + "002" + c + "-9999" + c + "-9999" + c + pressure dtemp_long_string(i) = message_type + c + st_id + c + full_time + c + lat + c + lon + c + "-9999" + c + "017" + c + "-9999" + c + "-9999" + c + dtemp wdir_long_string(i) = message_type + c + st_id + c + full_time + c + lat + c + lon + c + "-9999" + c + "031" + c + "-9999" + c + "-9999" + c + wdir wspd_long_string(i) = message_type + c + st_id + c + full_time + c + lat + c + lon + c + "-9999" + c + "032" + c + "-9999" + c + "-9999" + c + wspd delete(data_split) delete(st_id) delete(lat) delete(lon) delete(find_id) end do print(temp_long_string) asciiwrite("temp.txt",temp_long_string) asciiwrite("dtemp.txt",dtemp_long_string) asciiwrite("pres.txt",pres_long_string) asciiwrite("wdir.txt",wdir_long_string) asciiwrite("wspd.txt",temp_long_string) end