; load libraries, twice for good measure 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/wrf/WRFUserARW.ncl" ;load "/home/torn/ncl/wrf_map_info.ncl" ;load "/home/torn/ncl/array_stat.ncl" ;load "/home/torn/ncl/image_conv.ncl" 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/wrf/WRFUserARW.ncl" ;load "/home/torn/ncl/wrf_map_info.ncl" ;load "/home/torn/ncl/array_stat.ncl" ;load "/home/torn/ncl/image_conv.ncl" ;load "wrf_dart_util.ncl" begin fasc = "../*.txt" ; a unique identifier for file DASC = "./" ; output dir FASC = "BIG.txt" ; output file name system ("/bin/rm -f "+DASC+FASC) ; rm any pre-existing file ncol = stringtoint(systemfunc("ls -1 ../*.txt | wc -l")) ; Use UNIX "cat" to concatenate the files into one file. system ("cat "+fasc+" > "+DASC+FASC) ; You can now read the file via "asciiread". data = asciiread(DASC+FASC,(/ncol,365/),"float") system ("/bin/rm -f "+DASC+FASC) ; rm any pre-existing file ; meta files with info meta = asciiread("station.ascii", -1, "string") metadata = stringtofloat(meta(2:5)) ; figure out what days to plot daystring=new((/42/), "string") yearstring=new((/42/), "string") daynumber=new((/42/), "integer") official=new((/4,42/), "float") endpoint = asciiread("endpoint.txt",-1,"float") do i=-31,10,1 newi = i+endpoint(0) daystring(i+31) = tostring(systemfunc("date +%j -d "+newi+"days")) yearstring(i+31)= tostring(systemfunc("date +%y -d "+newi+"days")) daynumber(i+31) = tointeger(systemfunc("date +%j -d "+newi+"days")) end do ;reading in station data official(:,:) = -996 do i=-29,0,1 official(:,i+30) = asciiread(meta(1)+yearstring(i+30)+daystring(i+30)+".txt", -1, "float") end do ; getting right climo data do i=0,41,1 if daynumber(i).gt.daynumber(41) daynumber(i)=daynumber(i)-365 end if end do days = daynumber+365 ; read the water data, and calculate distance from site if needed delim = "," if metadata(3).eq.0 waterfile = "water.dat" waterdata = asciiread(waterfile,-1,"string") waterlats = tofloat(str_get_field(waterdata,3,delim)) waterlons = tofloat(str_get_field(waterdata,4,delim)) wateryes = tofloat(str_get_field(waterdata,5,delim)) distance = new((/dimsizes(waterlats)/),float) distance = 10000 do i = 0,dimsizes(waterlats)-1 distance(i) = gc_latlon(metadata(0),metadata(1),waterlats(i),waterlons(i),2,4) distance(i) = distance(i)*wateryes(i) end do distance@_FillValue = 0 print("Minimum distance to water for "+meta(1)+":"+min(distance)) else distance = metadata(3) end if ;;;;;;;;;Here's the order of data ;sdtmax(0-4),sdtmin(5-9),tavg(10-14),tmax(15-19),tmin(20-24),ytdp(25-28/9) temp=new((/8,365/), "float") temp(0,:)=data(15,:)+metadata(2)*data(16,:)+metadata(0)*data(17,:)+metadata(1)*data(18,:)+min(distance)*data(19,:) ; tmax temp(1,:)=temp(0,:)+(data(0,:)+metadata(2)*data(1,:)+metadata(0)*data(2,:)+metadata(1)*data(3,:))+min(distance)*data(4,:) ; tmax+ temp(2,:)=temp(0,:)-(data(0,:)+metadata(2)*data(1,:)+metadata(0)*data(2,:)+metadata(1)*data(3,:))+min(distance)*data(4,:) ; tmax- temp(3,:)=data(20,:)+metadata(2)*data(21,:)+metadata(0)*data(22,:)+metadata(1)*data(23,:)+min(distance)*data(24,:) ; tmin temp(4,:)=temp(3,:)+(data(5,:)+metadata(2)*data(6,:)+metadata(0)*data(7,:)+metadata(1)*data(8,:))+min(distance)*data(9,:) ; tmin+ temp(5,:)=temp(3,:)-(data(5,:)+metadata(2)*data(6,:)+metadata(0)*data(7,:)+metadata(1)*data(8,:))+min(distance)*data(9,:) ; tmin- temp(6,:)=data(10,:)+metadata(2)*data(11,:)+metadata(0)*data(12,:)+metadata(1)*data(13,:)+min(distance)*data(14,:) ; tavg temp(7,:)=.1*(data(25,:)+metadata(2)*data(26,:)+metadata(0)*data(27,:)+metadata(1)*data(28,:)) ; +min(distance)*data(29,:) ; precip - use last part if you have fixed problem temps = table_attach_columns(temp,temp,0) ; make two years worth of data to handle transition across year temps(7,365:729) = temps(7,365:729)+ temp(7,364) ; make sure precip is continuous window = temps(:,(days(0)-1):(days(41)-1)) official@_FillValue = -996 overlap=new((/2,42/), "float") overlap(0,:)=window(2,:) overlap(1,:)=window(4,:) overlap(0,:)=where(overlap(0,:).gt.overlap(1,:),overlap(1,:),overlap(0,:)) overlap(1,:)=where(overlap(0,:).gt.overlap(1,:),overlap(0,:),overlap(1,:)) precip = new((/2,730/), "float") precip(1,:) = temps(7,0:729) do i=1,729,1 precip(0,i) = 0 precip(1,i) = temps(7,i)-temps(7,i-1) end do precipwindow = precip(:,(days(0)-1):(days(41)-1)) precipreal = precipwindow if all(ismissing(official(2,:))) precipreal(1,:)=0 else precipreal(1,:)=cumsum(official(2,:),2) ; plot only real data end if ; get indices of value data, and only plot those indices=ind(.not.ismissing(official(0,:))) do xx = 0,(dimsizes(indices)-1) gg = indices(xx) end do ; get actual available highs/lows h = official(0,ind(.not.ismissing(official(0,:)))) l = official(1,ind(.not.ismissing(official(0,:)))) ; find expected monthly precip, but first check to make sure they exist pindices=ind(.not.ismissing(official(2,:))) if dimsizes(pindices).gt.1 pexpvalid = new((/dimsizes(pindices)/), "float") pvalid = new((/dimsizes(pindices)/), "float") do xx = 0,(dimsizes(pindices)-1) pexpvalid(xx) = precipwindow(1,pindices(xx)) pvalid(xx) = official(2,pindices(xx)) end do pflag = 0d else pexpvalid = 0.00 pvalid = 0.00 pflag = 1 end if p =sum(pvalid)-sum(pexpvalid) p =.01*round((100*p(0)),3) ; get various means expectedhigh = avg(window(0,ind(.not.ismissing(official(0,:))))) expectedlow = avg(window(3,ind(.not.ismissing(official(0,:))))) expectedmean = avg(window(6,ind(.not.ismissing(official(0,:))))) actualmean = (avg(h)+avg(l))/2 d = .1*round(10*(actualmean - expectedmean),3) ;w =.1*round(10*max(winds(1,:)),3) ;t =.01*round(100*max(cumsum(precip,2)),3) ;;;;;; temperature anomaly output ; write out daily anomaly, if it exists if .not.any(ismissing(official(0,30))) dayh = official(0,30) dayl = official(1,30) dayex= window(6,30) dayd = ""+tofloat(meta(2))+","+tofloat(meta(3))+","+(((dayh+dayl)/2)-dayex) quote = inttochar(34) system("echo "+quote+dayd(0)+quote+" >> daily.dat") dayd = ""+tofloat(meta(2))+","+tofloat(meta(3))+","+((dayh+dayl)/2) system("echo "+quote+dayd(0)+quote+" >> dailymean.dat") dayd = ""+tofloat(meta(2))+","+tofloat(meta(3))+","+dayh system("echo "+quote+dayd(0)+quote+" >> dailyhigh.dat") dayd = ""+tofloat(meta(2))+","+tofloat(meta(3))+","+dayl system("echo "+quote+dayd(0)+quote+" >> dailylow.dat") dayd = ""+tofloat(meta(2))+","+tofloat(meta(3))+","+(dayh-window(0,30)) system("echo "+quote+dayd(0)+quote+" >> dailyhighanomaly.dat") dayd = ""+tofloat(meta(2))+","+tofloat(meta(3))+","+(dayl-window(3,30)) system("echo "+quote+dayd(0)+quote+" >> dailylowanomaly.dat") heating = 0.0 cooling = 0.0 if ((dayh+dayl)/2).gt.65 cooling = ((dayh+dayl)/2) - 65 else if ((dayh+dayl)/2).lt.65 heating = ((dayh+dayl)/2) - 65 end if end if dayd = ""+tofloat(meta(2))+","+tofloat(meta(3))+","+heating*-1 system("echo "+quote+dayd(0)+quote+" >> dailyheating.dat") dayd = ""+tofloat(meta(2))+","+tofloat(meta(3))+","+cooling system("echo "+quote+dayd(0)+quote+" >> dailycooling.dat") end if ; write out weekly anomaly, if it exists if .not.any(ismissing(official(0,24:30))) weekh = official(0,24:30) weekl = official(1,24:30) weekex= window(6,24:30) weekd = ""+tofloat(meta(2))+","+tofloat(meta(3))+","+(((avg(weekh)+avg(weekl))/2)-avg(weekex)) quote = inttochar(34) system("echo "+quote+weekd(0)+quote+" >> weekly.dat") weekd = ""+tofloat(meta(2))+","+tofloat(meta(3))+","+((avg(weekh)+avg(weekl))/2) system("echo "+quote+weekd(0)+quote+" >> weeklymean.dat") dayd = ""+tofloat(meta(2))+","+tofloat(meta(3))+","+avg(weekh) system("echo "+quote+dayd(0)+quote+" >> weeklyhigh.dat") dayd = ""+tofloat(meta(2))+","+tofloat(meta(3))+","+avg(weekl) system("echo "+quote+dayd(0)+quote+" >> weeklylow.dat") dayd = ""+tofloat(meta(2))+","+tofloat(meta(3))+","+(avg(weekh)-avg(window(0,24:30))) system("echo "+quote+dayd(0)+quote+" >> weeklyhighanomaly.dat") dayd = ""+tofloat(meta(2))+","+tofloat(meta(3))+","+(avg(weekl)-avg(window(3,24:30))) system("echo "+quote+dayd(0)+quote+" >> weeklylowanomaly.dat") weekhc = (weekh + weekl)/2 heating = 0.0 cooling = 0.0 do i=0,6 if (weekhc(i).gt.65) cooling=cooling+(weekhc(i)-65) else if (weekhc(i).lt.65) heating=heating+(weekhc(i)-65) end if end if end do weekd = ""+tofloat(meta(2))+","+tofloat(meta(3))+","+heating*-1 system("echo "+quote+weekd(0)+quote+" >> weeklyheating.dat") weekd = ""+tofloat(meta(2))+","+tofloat(meta(3))+","+cooling system("echo "+quote+weekd(0)+quote+" >> weeklycooling.dat") end if ;write out monthly anomaly, if it exists if dimsizes(indices).gt.27 relative = ""+tofloat(meta(2))+","+tofloat(meta(3))+","+(actualmean-expectedmean) quote = inttochar(34) system("echo "+quote+relative(0)+quote+" >> monthly.dat") relative = ""+tofloat(meta(2))+","+tofloat(meta(3))+","+actualmean system("echo "+quote+relative(0)+quote+" >> monthlymean.dat") relative = ""+tofloat(meta(2))+","+tofloat(meta(3))+","+ avg(h) system("echo "+quote+relative(0)+quote+" >> monthlyhigh.dat") relative = ""+tofloat(meta(2))+","+tofloat(meta(3))+","+ avg(l) system("echo "+quote+relative(0)+quote+" >> monthlylow.dat") relative = ""+tofloat(meta(2))+","+tofloat(meta(3))+","+ (avg(h)-expectedhigh) system("echo "+quote+relative(0)+quote+" >> monthlyhighanomaly.dat") relative = ""+tofloat(meta(2))+","+tofloat(meta(3))+","+ (avg(l)-expectedlow) system("echo "+quote+relative(0)+quote+" >> monthlylowanomaly.dat") monthhc = (h + l)/2 heating = 0.0 cooling = 0.0 do i=0,(dimsizes(indices)-1) if (monthhc(i).gt.65) cooling=cooling+(monthhc(i)-65) else if (monthhc(i).lt.65) heating=heating+(monthhc(i)-65) end if end if end do monthd = ""+tofloat(meta(2))+","+tofloat(meta(3))+","+heating*-1 system("echo "+quote+monthd(0)+quote+" >> monthlyheating.dat") monthd = ""+tofloat(meta(2))+","+tofloat(meta(3))+","+cooling system("echo "+quote+monthd(0)+quote+" >> monthlycooling.dat") end if ;;;;; precip output ;write out precip monthly anomaly and total, if it exists if dimsizes(pindices).gt.27 relative = ""+tofloat(meta(2))+","+tofloat(meta(3))+","+(p) mrelative =""+tofloat(meta(2))+","+tofloat(meta(3))+","+ sum(pvalid) quote = inttochar(34) system("echo "+quote+relative(0)+quote+" >> precipmonthly.dat") system("echo "+quote+mrelative(0)+quote+" >> preciptotalmonthly.dat") end if ;write out precip weekly anomaly and total, if it exists if .not.any(ismissing(official(2,24:30))) pweeklyvalid = sum(official(2,24:30)) pexweekly = sum(precipwindow(1,24:30)) relative = ""+tofloat(meta(2))+","+tofloat(meta(3))+","+(pweeklyvalid-pexweekly) mrelative =""+tofloat(meta(2))+","+tofloat(meta(3))+","+ (pweeklyvalid) quote = inttochar(34) system("echo "+quote+relative(0)+quote+" >> precipweekly.dat") system("echo "+quote+mrelative(0)+quote+" >> preciptotalweekly.dat") end if if .not.any(ismissing(official(2,30))) pdailyvalid = sum(official(2,30)) pdailyex = sum(precipwindow(1,30)) mrelative =""+tofloat(meta(2))+","+tofloat(meta(3))+","+ (pdailyvalid) quote = inttochar(34) system("echo "+quote+mrelative(0)+quote+" >> preciptotaldaily.dat") pdailyanom = pdailyvalid-pdailyex mrelative =""+tofloat(meta(2))+","+tofloat(meta(3))+","+ (pdailyanom) system("echo "+quote+mrelative(0)+quote+" >> precipdaily.dat") end if ;;;;; write out solar data ; write out monthly average, if it exists sindices=ind(.not.ismissing(official(3,:))) solar = ((sum(official(3,:))*300)/1000000)/dimsizes(sindices) if dimsizes(sindices).gt.27 relative = ""+tofloat(meta(2))+","+tofloat(meta(3))+","+(solar) quote = inttochar(34) system("echo "+quote+relative(0)+quote+" >> solarmonthly.dat") end if ; write out weekly average, if it exists if .not.any(ismissing(official(3,24:30))) solar = ((sum(official(3,24:30))*300)/1000000)/7 relative = ""+tofloat(meta(2))+","+tofloat(meta(3))+","+(solar) quote = inttochar(34) system("echo "+quote+relative(0)+quote+" >> solarweekly.dat") end if ; write out daily total, if it exists if .not.any(ismissing(official(3,30))) solar = ((sum(official(3,30))*300)/1000000) relative = ""+tofloat(meta(2))+","+tofloat(meta(3))+","+(solar) quote = inttochar(34) system("echo "+quote+relative(0)+quote+" >> solardaily.dat") end if end