<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<style type="text/css" style="display:none;"><!-- P {margin-top:0;margin-bottom:0;} --></style>
</head>
<body dir="ltr">
<div id="divtagdefaultwrapper" style="font-size:12pt;color:#000000;font-family:Calibri,Helvetica,sans-serif;" dir="ltr">
<p>Hello,</p>
<p>I am trying to make a basic xy plot in NCL 5.2, and am getting the following error:</p>
<p><span>fatal:Number of subscripts do not match number of dimensions of variable,(1) Subscripts used, (2) Subscripts expected</span><br>
</p>
<p><span><br>
</span></p>
<p><span>I have looked at past questions that have the same error but cannot figure out how to apply their solutions to my script.</span></p>
<p><span>Any help would be much appreciated!</span></p>
<p><span>-Adam</span></p>
<p><span><br>
</span></p>
<p><span></p>
<div>;*************************************************</div>
<div>; plot_csv_example.ncl</div>
<div>;</div>
<div>; this script will plot data from csv/txt output</div>
<div>; for the columns you specify.</div>
<div>; please read through the code before you use it. It is currently set up to read in the csv file</div>
<div>; but not make the plot--you'll have to add code to make a plot.</div>
<div>;</div>
<div>;*************************************************</div>
<div>; first need to tell NCL where the function libraries are. These next 3 lines have to be at the top </div>
<div>; of EVERY NCL script you write:</div>
<div><br>
</div>
<div>load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"</div>
<div>load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"</div>
<div>load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl"</div>
<div><br>
</div>
<div>; after specifiying the paths you have to have a "begin script" statement:</div>
<div>begin</div>
<div><br>
</div>
<div>;************************************************************</div>
<div>; start user input</div>
<div>;************************************************************</div>
<div>; first designate the directory the directory where your csv file resides</div>
<div>filedir = "/users/hoefs/"</div>
<div><br>
</div>
<div>delim = ","</div>
<div><br>
</div>
<div>; specify filename</div>
<div>filename = "Houston2016.csv"</div>
<div><br>
</div>
<div>; specify column (number) of data to use on the x-axis of the plot</div>
<div>; note: though NCL usually starts counting at zero, when reading ascii/text/csv files</div>
<div>; the first column is numbered 1.</div>
<div>xcol = 1</div>
<div><br>
</div>
<div>; specify column (number) of data to use on the y-axis of the plot</div>
<div>ycol = 2</div>
<div><br>
</div>
<div>; specify the name of the output filename of the plot</div>
<div>; the script is currently set up to create a PDF plot. ".pdf" will be appended to the filename automatically</div>
<div>outfilename = "HoustonOzone2016"</div>
<div>; note that the output file is currently set up to be written to the same</div>
<div>; directory as the csv file</div>
<div><br>
</div>
<div>;************************************************************</div>
<div>; end user input</div>
<div>;************************************************************</div>
<div><br>
</div>
<div>file1 = ("/users/hoefs/Houston2016/")</div>
<div>; read in contents of file with "asciiread" function. Contents go into an array defined here as "values1d1"</div>
<div>values1d1 = asciiread("Houston2016.csv",-1,"string")</div>
<div>; use the str_split and dimsizes functions to get the number of columns</div>
<div>ncols = dimsizes(str_split(values1d1(1),","))</div>
<div>; use the dimsizes function to get the number of rows (includes header row(s) if there are any)</div>
<div>nrows = dimsizes(values1d1) ; this shouldn't change</div>
<div><br>
</div>
<div>; declare arrays to put data into. Adjust array size if there's a header row.</div>
<div>; for example, if there's a header row, xdata = new(nrows-1,float)</div>
<div>xdata = new(355,float)</div>
<div>ydata = new(355,float)</div>
<div><br>
</div>
<div>; note: if there is a header row (or rows) you'll need to change this loop</div>
<div>; for example, for a single header row change the length of the do loop to : do r = 1,nrows-2</div>
<div>; this loop reads in each row of values1d1 with the function "str_get_field" and then converts </div>
<div>; the string into a floating number with the "tofloat" function and stores the values in the xdata and ydata arrays.</div>
<div>do r = 0,nrows-1</div>
<div>   xdata(r) = tofloat(str_get_field(values1d1(r),xcol,","))</div>
<div>   ydata(r) = tofloat(str_get_field(values1d1(r),ycol,","))</div>
<div>end do</div>
<div><br>
</div>
<div>; here's an example of how to check that the data were read in correctly:</div>
<div>printVarSummary(ydata)</div>
<div>printMinMax(ydata,True)</div>
<div>print("the average is "+avg(ydata))</div>
<div><br>
</div>
<div><br>
</div>
<div>;**********************************************************</div>
<div>; now make the plot!</div>
<div>; a few basic things are included below but the bulk of the plotting commands you'll have to add.</div>
<div>; check the NCL example pages for how to make the kind of plot you want (xy scatter for example)</div>
<div><br>
</div>
<div>res = True</div>
<div>res@gsnFrame = False</div>
<div>res@xyLineThicknessF = 3</div>
<div>res@trYMinF = 0.0</div>
<div>res@trYMaxF = 0.1</div>
<div>res@trXMinF = 2016000</div>
<div>res@trXMaxF = 2016355</div>
<div>res@xyDashPattern = 0</div>
<div>res@xyLineColor = (/"NavyBlue"/)</div>
<div>res@tiXAxisString = "Date"</div>
<div>res@tiYAxisString = "Ozone Concentration (ppb)"</div>
<div><br>
</div>
<div>res@tiMainString = "8-Hr Max Daily Avg. Ozone Concentration in Houston 2016" ; title</div>
<div><br>
</div>
<div>outname = ("HoustonOzone") ; output filename</div>
<div><br>
</div>
<div>wks   = gsn_open_wks("pdf","HoustonOzone")</div>
<div><br>
</div>
<div>res@gsnMaximize          = True</div>
<div>res@gsnPaperOrientation  = "Landscape"</div>
<div>val = new((/1,355/),float)</div>
<div>x = 2016000 + ispan(0,355,1)</div>
<div><br>
</div>
<div><span style="font-size: 12pt;">plot = gsn_csm_xy(wks,x(r),val(r),res)</span><br>
</div>
<div>draw(plot)</div>
<div>frame(wks)</div>
<div><br>
</div>
<div><br>
</div>
<div>end  ; obligatory "end of script" statement</div>
<div><br>
</div>
<br>
</span>
<p></p>
</div>
</body>
</html>