func plts (vari, xi, lab=, labx=, color=, width=, runmn=, xp=, rng=, mean=, mnmx=, type=, mean_color=, trend_color=, mnmx_color=,twt=) /* DOCUMENT plts, var, x, lab=, labx, color=, width=, xp=, rng=, mean=, mnmx=, type= Makes time series line plots, versus x, with an optional label. The function is really designed for monthly data with x in years. runmn=12: compute 12 month running means and perform all other operations on the means. runmn may be any other number also. xp=(first,last): times to compute trend over, print trend/century rng=1: annual range, shaded in using plfp, color index 1. mean=index: line plotted for mean of series starting at index. mnmx=index: horizontal lines plotted for min and max values starting at index. color = COLOR, color to plot data with (e.g., "blue") mean_color=, trend_color=, mnmx_color= colors for plot parts, default to COLOR, trend_color="none", means omit trend line. twt = time weights for running means, normally to [31,28,31,30,31,30,31,31,30,31,30,31] repeating for monthly data. */ { require, "fitlsq.i"; nt = numberof(xi); ny = nt/12; if (is_void(color)) color="black"; if (is_void(type)) type ="solid"; if (is_void(mean_color)) mean_color=color; if (is_void(mnmx_color)) mnmx_color=color; if (is_void(trend_color)) trend_color=color; port = viewport(); /* compute running means if requested */ if (!is_void(runmn)) { if (is_void(twt)) { if ((runmn == 12) && (nt%12 == 0)) { for (iy=1;iy<=ny;iy++) { twt = grow(twt,[31,28,31,30,31,30,31,31,30,31,30,31]); } } else { twt = array(1.,nt); } } var = array(float, nt+1-runmn); x = array(float, nt+1-runmn); for (t=1; t<=nt+1-runmn; t++) { var(t) = (vari(t:t+runmn-1)*twt(t:t+runmn-1))(sum)/twt(sum:t:t+runmn-1) ; x(t) = xi(avg:t:t+runmn-1); } nt = numberof(x); ny = nt/runmn; } else { var = vari; x = xi; } /* plot annual range, putting values near year midpoints */ if (is_void(rng) || (rng == 0)) { plg, var ,x, marks=0, color=color, width=width, type=type; } else { mn_an = array(double, ny); mx_an = array(double, ny); mn_tt = array(double, ny); mx_tt = array(double, ny); tt = 0; for (t=1; t<=nt-11; t=t+12) { tt = tt+1; mn_an(tt) = var(min:t:t+11); mn_tt(tt) = x (t+5); mx_an(tt) = var(max:t:t+11); mx_tt(tt) = x (t+5); } if (rng == 1) { rngf = grow(mn_an, mx_an(0:1:-1)); ttxx = grow(mn_tt, mx_tt(0:1:-1)); plfp, [char(0)], rngf, ttxx, numberof(rngf); } else { plg,mn_an,mn_tt,marks=0,color=color,width=width; plg,mx_an,mx_tt,marks=0,color=color,width=width; } } /* plot label */ if (!is_void(lab)) plt, lab, port(1)+.01, port(4)-.005, justify="LT", height=14.; /* compute trend and plot label and mean of field */ if (!is_void(xp)) { yp = fitlsq(var, x, xp); trend = (yp(2) - yp(1)) / (xp(2) - xp(1)) * 100; print,"trend/century:", trend; // plt, "trend: " + pr1(trend) + " / century", // port(2)-.01, port(4)-.005, justify="RT", height=14, color=color; if(trend_color != "none") plg,yp,xp,marks=0,color=trend_color,width=2; } /* compute and plot mean of series */ if (!is_void(mean)) { meanv = var(avg:mean:); plg,[meanv,meanv],[x(mean),x(0)],marks=0,color=mean_color,width=2; } /* plot horizontal lines for min and max of field since time index*/ if (!is_void(mnmx)) { tmin = var(min:mnmx:); tmax = var(max:mnmx:); plg,[tmin,tmin],[x(mnmx),x(0)],marks=0,color=mnmx_color,width=2; plg,[tmax,tmax],[x(mnmx),x(0)],marks=0,color=mnmx_color,width=2; } if (!is_void(labx)) plt, labx, avg(port(1:2)), port(3)-.025, justify="CT",height=14; if (!is_void(xp)) return trend; }