<div dir="ltr"><div class="gmail_default" style="font-size:small">There are a number of issues with your script. <br></div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">[1]</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">By default, when you pull a variable off a set of files opened with "addfiles", they are "concatenated" (this is known as "cat" mode in NCL) across the leftmost dimension.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">If you use the "join" mode, then a new leftmost dimension will be created that will be the same size as the number of files (in your case, 20).</div><div class="gmail_default" style="font-size:small"><font color="#000000"><br></font></div><div class="gmail_default" style="font-size:small"><font color="#000000">To get "join" mode, uncomment your ListSetType option above and change it to:</font></div><div class="gmail_default" style="font-size:small"><font color="#000000"><br></font></div><div class="gmail_default" style="font-size:small"><font color="#000000" face="monospace, monospace"><span style="font-size:12.8px"> ListSetType (f, "join") ;join files</span><br style="font-size:12.8px"></font></div><div class="gmail_default" style="font-size:small"><font color="#000000" face="monospace, monospace"><span style="font-size:12.8px"><br></span></font></div><div class="gmail_default" style="font-size:small">[2] </div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style=""><span style="font-size:12.8px"><font color="#000000">To get a 4 x 5 configuration rather than a 20 configuration, you can use reshape to change the dimensions:</font></span></div><div class="gmail_default" style=""><span style="font-size:12.8px"><font color="#000000" face="monospace, monospace"><br></font></span></div><div class="gmail_default" style=""><font color="#000000" face="monospace, monospace"><span style="font-size:12.8px"> npp_dims = filevardimsizes(f[0],"</span><span style="font-size:12.8px">Npp_1km_</span><span style="font-size:12.8px">MOD_Grid_MOD17A3")<br></span></font></div><div class="gmail_default" style=""><span style="color:rgb(0,0,0);font-family:monospace,monospace;font-size:12.8px"> npp = reshape(short2flt(f[:]->Npp_1km_</span><span style="color:rgb(0,0,0);font-family:monospace,monospace;font-size:12.8px">MOD_Grid_MOD17A3),(/4,5,npp_dims(0),npp_dims(1)/))</span></div><div class="gmail_default" style=""><br></div><div class="gmail_default" style=""><div class="gmail_default"><font color="#000000" face="arial, helvetica, sans-serif"><span style="font-size:12.8px"><br class="">Please see the documentation for "addfiles" for more information:</span></font></div><div class="gmail_default"><font color="#000000" face="arial, helvetica, sans-serif"><span style="font-size:12.8px"><br></span></font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif" color="#000000"><span style="font-size:12.8px"><a href="http://www.ncl.ucar.edu/Document/Functions/Built-in/addfiles.shtml">http://www.ncl.ucar.edu/Document/Functions/Built-in/addfiles.shtml</a></span></font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif" color="#000000"><br></font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif" color="#000000">[3]</font></div><div class="gmail_default"><font face="arial, helvetica, sans-serif" color="#000000"><br></font></div></div><div class="gmail_default" style=""><span style="color:rgb(0,0,0);font-size:12.8px"><font face="arial, helvetica, sans-serif">An issue with using reshape is that you may lose attribute and coordinate information, if any. </font></span><span style="font-family:arial,helvetica,sans-serif;color:rgb(0,0,0);font-size:12.8px">You can use copy_VarAtts and copy_VarCoords to copy over any information you need. </span></div><div class="gmail_default" style=""><span style="color:rgb(0,0,0);font-size:12.8px"><font face="arial, helvetica, sans-serif"><br></font></span></div><div class="gmail_default" style=""><span style="color:rgb(0,0,0);font-size:12.8px"><font face="arial, helvetica, sans-serif">See:</font></span></div><div class="gmail_default" style=""><span style="color:rgb(0,0,0);font-size:12.8px"><font face="arial, helvetica, sans-serif"><br></font></span></div><div class="gmail_default" style=""><font face="arial, helvetica, sans-serif"><font color="#000000"><span style="font-size:12.8px"><a href="http://www.ncl.ucar.edu/Document/Functions/Contributed/copy_VarAtts.shtml">http://www.ncl.ucar.edu/Document/Functions/Contributed/copy_VarAtts.shtml</a></span></font><br></font></div><div class="gmail_default" style=""><font color="#000000" face="arial, helvetica, sans-serif"><span style="font-size:12.8px"><a href="http://www.ncl.ucar.edu/Document/Functions/Contributed/copy_VarCoords.shtml">http://www.ncl.ucar.edu/Document/Functions/Contributed/copy_VarCoords.shtml</a></span><br></font></div><div class="gmail_default" style=""><font color="#000000" face="arial, helvetica, sans-serif"><span style="font-size:12.8px"><br>[4]</span></font></div><div class="gmail_default" style=""><font color="#000000" face="arial, helvetica, sans-serif"><span style="font-size:12.8px"><br></span></font></div><div class="gmail_default" style=""><font color="#000000" face="arial, helvetica, sans-serif"><span style="font-size:12.8px">You are reading two-dimensional latitude and longitude arrays off the file, and then trying to treat them as coordinate arrays with:</span></font></div><div class="gmail_default" style=""><font color="#000000" face="monospace, monospace"><span style="font-size:12.8px"><br></span></font></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_default" style=""><font color="#000000"><font face="monospace, monospace"><span style="font-size:12.8px">npp!0="lat2d"</span></font></font></div><div class="gmail_default" style=""><font color="#000000"><font face="monospace, monospace"><span style="font-size:12.8px">npp!1="lon2d"</span></font></font></div><div class="gmail_default" style=""><font color="#000000"><font face="monospace, monospace"><span style="font-size:12.8px">npp&lat2d=lat2d</span></font></font></div><div class="gmail_default" style=""><font color="#000000"><font face="monospace, monospace"><span style="font-size:12.8px">npp&lon2d=lon2d</span></font></font></div></blockquote><div class="gmail_default" style=""><span style="font-size:12.8px"><font color="#000000"><br></font></span></div><div class="gmail_default" style=""><span style="font-size:12.8px"><font color="#000000">By strict definition, coordinate arrays can only be one-dimensional, and of the same size as whatever dimension they are associated with. Since your lat/lon arrays are 2D, you cannot assign them as coordinate arrays. </font></span></div><div class="gmail_default" style=""><span style="font-size:12.8px"><font color="#000000"><br></font></span></div><div class="gmail_default" style=""><span style="font-size:12.8px"><font color="#000000">You can, however, write them separately to the file just like your "npp" variable, and then create a "coordinates" attribute (that I see you have already) that indicates what the name of the lat/lon arrays are on the new file:</font></span></div><div class="gmail_default" style=""><span style="font-size:12.8px"><font color="#000000"><br></font></span></div><blockquote style="margin:0px 0px 0px 40px;border:none;padding:0px"><div class="gmail_default" style=""><font color="#000000" face="monospace, monospace"><span style="font-size:12.8px">npp@coordinates="lon2d lat2d"</span></font></div></blockquote><div class="gmail_default" style=""><span style="font-size:12.8px"><font color="#000000"><br></font></span></div><div class="gmail_default" style=""><span style="font-size:12.8px"><font color="#000000">Note that the "coordinates" attribute generally doesn't have a comma in it. Also, if your "npp" variable is 4D, and the other two dimensions have variables associated with them, you'll want to include these in the "coordinates" setting. For example, if you had a 3D array, and the leftmost dimension was represented by a variable on the file called "time", then you would use:</font></span></div><div class="gmail_default" style=""><span style="font-size:12.8px"><font color="#000000"><br></font></span></div><div class="gmail_default" style=""><span style="font-size:12.8px"><font color="#000000">npp@coordinates = "lon2d lat2d time"</font></span></div><div class="gmail_default" style=""><span style="font-size:12.8px"><font color="#000000"><br></font></span></div><div class="gmail_default" style=""><span style="font-size:12.8px"><font color="#000000">For some reason, the coordinates are usually listed right-to-left, although I don't think this is required.</font></span></div><div class="gmail_default" style=""><span style="font-size:12.8px"><font color="#000000"><br></font></span></div><div class="gmail_default" style=""><span style="font-size:12.8px"><font color="#000000">[5]</font></span></div><div class="gmail_default" style=""><span style="font-size:12.8px"><font color="#000000"><br></font></span></div><div class="gmail_default" style=""><span style="font-size:12.8px"><font color="#000000">You should use the same dimension names for your "npp" variable that you have for the lat2d/lon2d variables:</font></span></div><div class="gmail_default" style=""><span style="font-size:12.8px"><font color="#000000"><br></font></span></div><div class="gmail_default" style=""><span style="font-size:12.8px"><font color="#000000">npp!2 = "nlat"</font></span></div><div class="gmail_default" style=""><span style="font-size:12.8px"><font color="#000000">npp!3 = "nlon"</font></span></div><div class="gmail_default" style=""><span style="font-size:12.8px"><font color="#000000"><br></font></span></div><div class="gmail_default" style=""><span style="font-size:12.8px"><font color="#000000">Note that I changed these to dimensions 2 and 3, because dimensions 0 and 1 are associated with the "4 x 5" part of your array. You will need to name these accordingly.</font></span></div><div class="gmail_default" style=""><br></div><div class="gmail_default" style=""><font color="#000000" face="arial, helvetica, sans-serif"><span style="font-size:12.8px"><br></span></font></div><div class="gmail_default" style=""><font color="#000000"><span style="font-size:12.8px">--Mary</span></font></div><div class="gmail_default" style=""><font color="#000000"><span style="font-size:12.8px"><br></span></font></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Wed, Dec 9, 2015 at 5:13 AM, Abdulla Sakalli <span dir="ltr"><<a href="mailto:as@abdulla-sakalli.com" target="_blank">as@abdulla-sakalli.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<div style="word-wrap:break-word" text="#000000" bgcolor="#FFFFFF">
Dear List,
<div><br>
</div>
<div>I downloaded 20 files from MODIS satellite for NPP (MOD17A3).
I’d like to read the hdf files and merge it in 4x5 to get the NPP
value for pan-European domain. I've been written the fallowing
script for my aim. Unfortunately, I get the files merged in 1x20
(i.e. merged along latitude and not lonxlat direction).<br>
Can please anyone help me to read the npp from the 20 files and
enlarge it in LonxLat direction.<br>
<br>
Thank you very much in advance<br>
Abu<br>
<br>
Script:<br>
<br>
<br>
</div>
<div><font color="#ff0000"><br>
</font></div>
<div><font color="#ff0000">load
"$NCARG_ROOT/share/ncarg/nclscripts/csm/gsn_code.ncl"<br>
load "$NCARG_ROOT/share/ncarg/nclscripts/csm/gsn_csm.ncl"<br>
load "$NCARG_ROOT/share/ncarg/nclscripts/csm/contributed.ncl"<br>
load "$NCARG_ROOT/share/ncarg/nclscripts/csm/shea_util.ncl"<br>
<br>
begin<br>
<br>
; 1km annual npp MOD17A3 on 1200x1200 tiles<br>
<br>
files = systemfunc("ls *.hdfeos")<br>
<br>
f = addfiles(files,"r")<br>
;print(f)<br>
;ListSetType (f, "cat") ;concatenate files<br>
<br>
lat2d=f[:]->GridLat_MOD_Grid_MOD17A3<br>
lon2d=f[:]->GridLon_MOD_Grid_MOD17A3<br>
<br>
npp=short2flt(f[:]->Npp_1km_MOD_Grid_MOD17A3)<br>
<br>
lat2d!0="nlat"<br>
lat2d!1="nlon"<br>
lon2d!0="nlat"<br>
lon2d!1="nlon"<br>
<br>
;printVarSummary(lon2d)<br>
<br>
npp!0="lat2d"<br>
npp!1="lon2d"<br>
npp&lat2d=lat2d<br>
npp&lon2d=lon2d<br>
npp@coordinates="lat2d,lon2d"<br>
npp@projection="sinusoidal"<br>
<br>
printVarSummary(npp)<br>
<br>
system("rm <a href="http://test.nc" target="_blank">test.nc</a>")<br>
out=addfile("<a href="http://test.nc" target="_blank">test.nc</a>","c")<br>
out->npp=npp<br>
out->lat2d=lat2d<br>
out->lon2d=lon2d<br>
<br>
end<br>
</font></div>
<div><br>
</div>
<div><i><small>print summary is<br>
<br>
Variable: npp<br>
Type: short<br>
Total Size: 57600000 bytes<br>
28800000 values<br>
Number of Dimensions: 2<br>
Dimensions and sizes: [YDim_MOD_Grid_MOD17A3 | 24000] x
[XDim_MOD_Grid_MOD17A3 | 1200]<br>
Coordinates: <br>
Number Of Attributes: 6<br>
lon2d : <ARRAY of 28800000 elements><br>
lat2d : <ARRAY of 28800000 elements><br>
coordinates : lat2d,lon2d<br>
hdfeos_name : Npp_1km<br>
projection : sinusoidal<br>
unsigned : True<br>
</small></i><br>
</div>
<div><br>
<div>
<div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div style="color:rgb(0,0,0);letter-spacing:normal;text-align:start;text-indent:0px;text-transform:none;white-space:normal;word-spacing:0px;word-wrap:break-word"><div><div style="word-wrap:break-word"><div style="word-wrap:break-word"><div><font color="#aaaaaa">---------------------------------------------------------------------------<br>Asst. Prof. Abdulla Sakalli<br><br></font><font color="#aaaaaa">Iskenderun Technical University</font></div><div><font color="#aaaaaa">Faculty of Marine Sciences & Technology<br>Dept. Water Resources Management and Organization<br>Meydan Mah. 512 Sk<br>Iskenderun-Hatay-Turkey<br></font></div><div><a href="http://www.abdulla-sakalli.com" target="_blank">as@abdulla-sakalli.com</a></div><div><a href="mailto:asakalli@mku.edu.tr" target="_blank">asakalli@istek.edu.tr</a><font color="#aaaaaa"><br><a href="tel:%2B90%20326%20614%201693" value="+903266141693" target="_blank">+90 326 614 1693</a> (330)<br><a href="tel:%2B90%20536%20506%209191" value="+905365069191" target="_blank">+90 536 506 9191</a></font></div><div><font color="#aaaaaa"><br></font></div></div></div></div></div><br></div><br></div><br></div><br><br>
</div>
<br>
</div>
</div><br>_______________________________________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@ucar.edu">ncl-talk@ucar.edu</a><br>
List instructions, subscriber options, unsubscribe:<br>
<a href="http://mailman.ucar.edu/mailman/listinfo/ncl-talk" rel="noreferrer" target="_blank">http://mailman.ucar.edu/mailman/listinfo/ncl-talk</a><br>
<br></blockquote></div><br></div>