<div dir="ltr"><div><div>Hi Mary,<br><br></div>Thank you for your response. Sorry I could not respond you back earlier but I was away for couple of weeks. I ran the code by implementing your suggestion but it still did not solve the issue. I made the changes as you suggested as.given below (attached) and created netcdf file has very weird metadata structure. ncl11, ncl12, ncl13, ....(attached at the end).<br><br>load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"<br>load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_csm.ncl"<br><br>; setfileoption("nc", "FileStructure", "Advanced")<br><br>fn = "C:\Users\Downloads\Newfolder\MERRA2_200.inst3_3d_asm_Nv.19950203.nc4"<br>fn1 = "C:\Users\Downloads\Newfolder\MERRA2_200.inst3_3d_gas_Nv.19950203.nc4"<br><br> fi = addfile(fn, "r")<br>fi1= addfile(fn1, "r")<br><br>; setfileoption("nc", "Format", "NetCDF4Classic")<br><br> printVarSummary(fi)<br>;print(fi)<br> time = fi->time<br> lev = fi->lev<br> lat = fi->lat<br> lon = fi->lon<br> h = fi->H<br> ;u = fi->U;(:,:,264,108)<br>; v = fi->V;(:,:,264,108)<br> w=fi->OMEGA;(:,:,264,108)<br> p=fi->PL;(:,:,264,108)<br>den=fi1->AIRDENS;(:,:,264,108)<br>hm=h(:,:,264,108)<br>;uh=u(:,:,264,108)<br>;uv=v(:,:,264,108)<br>wv=w(:,:,264,108)<br>pv=p(:,:,264,108)<br>denv=den(:,:,264,108)<br>;printVarSummary(u)<br>printVarSummary(denv)<br>printVarSummary(wv)<br>printMinMax(wv,True)<br>wv!0="time"<br>wv!1="lev"<br>wv&time=time<br>wv&lev=lev<br>denv!0="time"<br>denv!1="lev"<br>denv&time=time<br>denv&lev=lev<br>n=dimsizes(wv)<br>n1=dimsizes(time)<br>n2=dimsizes(lev)<br>;wc=new((/n1,n2/),"float")<br>;do i=0,n1-1<br>;wc(i,:)=wv(i,:)/(-9.8*denv(i,:))<br>;end do<br>;wc=wv<br>;wc=(wv(time|:,lev|:)/(-9.8*denv(time|:,lev|:)))<br>wc=(wv/(-9.8*denv))<br>copy_VarMeta(wv,wc)<br>printMinMax(wc,True)<br>;newlat=lat(108)<br>;newlon=lon(264)<br>wc!0="time"<br>wc!1="lev"<br>wc&time=time<br>wc&lev=lev<br>printVarSummary(wc)<br>dataf = wc<br>;dataf = newdatan(lon|:,lev|:,time|:,lat|:)<br>printVarSummary(dataf)<br>;print(time)<br>;return<br>;Writeout new netCDF file<br>wc&time = time<br>wc&lev = lev<br>;dataf!0="time"<br>;dataf!1="lev"<br>;dataf&time=time<br>;dataf&lev=lev<br>;wc&lat = newlat<br>;wc&lon = newlon<br>ncdf=addfile("C:/Users/Downloads/Newfolder/MERRA_19950203nwww.nc","c")<br>dataf!0="time"<br>dataf!1="lev"<br>dataf&time=time<br>dataf&lev=lev<br>ncdf->time= (/time/)<br>ncdf->lev= (/lev/)<br>ncdf->data2=(/dataf/)<br>ncdf->data3=(/pv/)<br>;ncdf->data4=(/uv/)<br>;ncdf->data5=(/uh/)<br>ncdf->data6=(/hm/)<br>return<br>;return<br>;printVarSummary(v)<br>return<br>;print("t(0,0,0,0) = " + t(0,0,0,0))<br>;print("u(0,1,1,1) = " + u(0,1,1,1))<br>;print("v(0,2,2,2) = " + v(0,2,2,2))<br>;print("t&lat(0) = " + t&lat(0))<br>;print("t@units = " + t@units)<br>;print("u@units = " + u@units)<br>;print("v@units = " + v@units)<br>;u1 = fi->U(::2)<br>;v1 = fi->V(3:121:3)<br> ;;g1 = fi=>/grp1<br> ;;print(g1)<br> ;;printVarSummary(g1)<br>;exit<br> ;;uf = fi->V<br> ;;wks = gsn_open_wks("x11", "xy")<br><br>;; res = True<br> ;;res@tiMainString = "Basic plot" <br><br> ;;plot1 = gsn_csm_contour(wks, uf(0,0,:,:), False)<br><br> ;;ug = g1->V<br><br> ;;plot2 = gsn_csm_contour(wks, ug(0,0,:,:), False)<br>;;return<br>;end<br><br></div>The NetCDF file I created has the metadata as below,<br><div>
<pre>netcdf file:/C:/Users/Downloads/Newfolder/MERRA_19950203nwww.nc {
dimensions:
ncl0 = 8;
ncl1 = 72;
ncl2 = 8;
ncl3 = 72;
ncl4 = 8;
ncl5 = 72;
ncl6 = 8;
ncl7 = 72;
variables:
int time(ncl0=8);
double lev(ncl1=72);
float data2(ncl2=8, ncl3=72);
float data3(ncl4=8, ncl5=72);
float data6(ncl6=8, ncl7=72);
}
</pre>
Thanks again.<br><br></div><div>Dipti<br></div><div><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Jul 17, 2017 at 12:34 AM, Mary Haley <span dir="ltr"><<a href="mailto:haley@ucar.edu" target="_blank">haley@ucar.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div class="gmail_default" style="font-size:small">Dear Dipti,</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">I'm sorry, but I missed that you had a second question imbedded in this email.</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">Were you able to get the metadata added to "wc"?</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default" style="font-size:small">The reason it doesn't have metadata like "var" is because when you do a calculation and assign it to a variable that doesn't exist:</div><div class="gmail_default" style="font-size:small"><br></div><div class="gmail_default">wc=(wv/(-9.8*denv))<br></div><div class="gmail_default"><br></div><div class="gmail_default">then "wc" will not inherit any metadata from wv or denv except the _FillValue attribute.</div><div class="gmail_default"><br></div><div class="gmail_default">In order to get metadata, you either need to do a direct variable copy first, so that "wc" gets metadata before doing the calculation:</div><div class="gmail_default"><br></div><div class="gmail_default"><div class="gmail_default">wc=wv ; Trick to copy metadata from wv to wc (values also get copied)<br></div><div><div class="gmail_default">wc=(wc/(-9.8*denv))<br></div></div><div class="gmail_default"><br></div><div class="gmail_default">or you can use copy_VarMeta:</div><div class="gmail_default"><br></div><div class="gmail_default"><div class="gmail_default">wc=(wv/(-9.8*denv))<br></div><div>copy_VarMeta(wv,wc) ; copy wv's metadata to wc</div><div><br></div><div>In either case, you should update the long_name/standard_name and units attributes of wc to correctly reflect what they are.</div><span class="HOEnZb"><font color="#888888"><div><br></div><div>--Mary</div><div><br></div></font></span></div><div><br></div></div></div><div class="HOEnZb"><div class="h5"><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jun 29, 2017 at 5:12 PM, Dipti Sharma <span dir="ltr"><<a href="mailto:sdipti596@gmail.com" target="_blank">sdipti596@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div><div><div>Hi Mary,<br><br></div>Thank you. It worked now. I also made file name little shorter then that worked.<br><br><span style="font-size:12.8px">ncdf=addfile("/Users/</span><span style="font-size:12.8px">Downloads<wbr>/New\ folder/</span>MERRA_19950830.nc","c")<br></div><div>but one thing, when I do printVarSummay(var) I get the var info with 2dimensions <br><br>Number of Dimensions: 2<br>Dimensions and sizes: [time | 8] x [lev | 72]<br>Coordinates: <br> time: [0..1260]<br> lev: [ 1.. 72]<br>Number Of Attributes: 13<br> lon : -112.5<br> lat : 42<br> valid_range : ( -1e+15, 1e+15 )<br> vmin : -1e+15<br> vmax : 1e+15<br> standard_name : air_density<br> add_offset : 0<br> scale_factor : 1<br> fmissing_value : 1e+15<br> missing_value : 1e+15<br> _FillValue : 1e+15<br> units : kg m-3<br><br></div><div>But for wc, when I do printVarSummay(wc)<br>Variable: wc<br>Type: float<br>Total Size: 2304 bytes<br> 576 values<br>Number of Dimensions: 2<br>Dimensions and sizes: [8] x [72]; There is different format so how to get this like ' [time | 8] x [lev | 72]'?<br><br>Coordinates: <br>Number Of Attributes: 1<br> _FillValue : 1e+15<br>(0) <br>(0) min=-0.0658635 max=0.0909946<br><br></div><div>ALSO, my necdf file is not looking with correct attributes,<br><br>
<pre>netcdf file:/C:/Users/Downloads/New%2<wbr>0folder/MERRA2_19950830.nc {
dimensions:
ncl0 = 8; should be time=8; <br> ncl1 = 72;lev=72; etc.
ncl2 = 8;
ncl3 = 72;
variables:
int time(ncl0=8);
double lev(ncl1=72);
float data2(ncl2=8, ncl3=72);
}
</pre>
<br></div>Thank you so much again.<span class="m_5645409875622966119HOEnZb"><font color="#888888"><br><br></font></span></div><span class="m_5645409875622966119HOEnZb"><font color="#888888">Dipti</font></span><div><div class="m_5645409875622966119h5"><br><div><div><br></div><div class="gmail_extra"><br><div class="gmail_quote">On Thu, Jun 29, 2017 at 11:49 AM, Mary Haley <span dir="ltr"><<a href="mailto:haley@ucar.edu" target="_blank">haley@ucar.edu</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr"><div style="font-size:small">Hi Dipti,</div><div style="font-size:small"><br></div><div style="font-size:small">I'm not sure that addfile can recognize Windows type of directory paths with "C:\....".</div><div style="font-size:small"><br></div><div style="font-size:small">Try using UNIX-style paths:</div><div style="font-size:small"><br></div><div style="font-size:small"><span style="font-size:12.8px">ncdf=addfile("/Users/</span><span style="font-size:12.8px">Downloads<wbr>/New\ folder/</span><a href="http://merra2_200.inst3_3d_asm_nv.19950830.nc/" style="font-size:12.8px" target="_blank">MERRA2_200.inst3_3d_asm<wbr>_Nv.19950830.nc</a><span style="font-size:12.8px">","c")</span><br style="font-size:12.8px"></div><div style="font-size:small"><br></div><div style="font-size:small">Note that I used forward slashes ('/') instead of backward slashes ('\'). However, since you have a space in one of your directory names----"New folder"---I put a backward slash in front of the space, just in case.</div><div style="font-size:small"><br></div><div style="font-size:small">--Mary</div><div style="font-size:small"><br></div></div><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="m_5645409875622966119m_5583139399802477319h5">On Wed, Jun 28, 2017 at 5:55 PM, Dipti Sharma <span dir="ltr"><<a href="mailto:sdipti596@gmail.com" target="_blank">sdipti596@gmail.com</a>></span> wrote:<br></div></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div><div class="m_5645409875622966119m_5583139399802477319h5"><div dir="ltr"><div>Dear NCL,<br><br></div><div>I am trying to write netCDF file for selected variable (wc, the vertical velocity here in this example) from MERRA-2 wind data. However, I always get an error message saying that<br> " fatal:Could not create (C:\Users\Downloads\New folder\<a href="http://MERRA2_200.inst3_3d_asm_Nv.19950830.nc" target="_blank">MERRA2_200.inst3_3d_asm<wbr>_Nv.19950830.nc</a>)<br><br></div><div>Could someone please help me how to write the output file in netCDF. I want to have wc (time,lev) 2D data from 4D (time, lev,lat,lon). I just want the data at 1 location (1 lat and 1 lon).<br><br></div><div>Thank you very much in advance for your help.<br><br></div><div>Regards,<br><br></div><div>Dipti<br></div><div><br></div><div>Attached is the script that I used to read the data.<br></div><div><br></div><div><br>load "$NCARG_ROOT/lib/ncarg/nclscri<wbr>pts/csm/gsn_code.ncl"<br>load "$NCARG_ROOT/lib/ncarg/nclscri<wbr>pts/csm/gsn_csm.ncl"<br><br>; setfileoption("nc", "FileStructure", "Advanced")<br><br>fn = "C:\Users\Downloads\New folder\MERRA2_200.inst3_3d_asm<wbr>_Nv.19950830.nc4"<br>fn1 = "C:\Users\Downloads\New folder\MERRA2_200.inst3_3d_gas<wbr>_Nv.19950830.nc4"<br><br> fi = addfile(fn, "r")<br>fi1= addfile(fn1, "r")<br><br>; setfileoption("nc", "Format", "NetCDF4Classic")<br><br> printVarSummary(fi)<br>;print(fi)<br><br> time = fi->time<br> lev = fi->lev<br> lat = fi->lat<br> lon = fi->lon<br> u = fi->U;(:,:,269,101)<br> v = fi->V;(:,:,269,101)<br> w=fi->OMEGA;(:,:,269,101)<br> p=fi->PL;(:,:,269,101)<br>den=fi1->AIRDENS;(:,:,269,101)<br>uh=u(:,:,269,101)<br>uv=v(:,:,269,101)<br>wv=w(:,:,269,101)<br>pv=PL(:,:,269,101)<br>denv=den(:,:,269,101)<br>;printVarSummary(u)<br>printVarSummary(denv)<br>printVarSummary(wv)<br>printMinMax(wv,True) <br></div>;calculate vertical velocity<br><div>wc=(wv/(-9.8*denv))<br>printVarSummary(wc)<br>printMinMax(wc,True)<br>wc!0="time"<br>wc!1="lev"<br>;wc!2="lat"<br>;wc!3="lon"<br>datad = wc;(time|:,lev|:)<br>printVarSummary(datad)<br><br>;Writeout new netCDF file<br><br>wc&time = time<br>wc&lev = lev<br>ncdf=addfile("C:\Users\Downloa<wbr>ds\New folder\<a href="http://MERRA2_200.inst3_3d_asm_Nv.19950830.nc" target="_blank">MERRA2_200.inst3_3d_asm<wbr>_Nv.19950830.nc</a>","c")<br>ncdf->time= (/time/)<br>ncdf->lev= (/lev/)<br>ncdf->data=(/datad/)<br>return<br></div><div>end<br></div><div><div class="gmail_extra"><br><br></div></div></div>
<br></div></div>______________________________<wbr>_________________<br>
ncl-talk mailing list<br>
<a href="mailto:ncl-talk@ucar.edu" target="_blank">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/mailma<wbr>n/listinfo/ncl-talk</a><br>
<br></blockquote></div><br></div>
</blockquote></div><br></div></div></div></div></div>
</blockquote></div><br></div>
</div></div></blockquote></div><br></div>