<div dir="ltr"><div>Keep in mind:</div><div><br></div><div>NCL arrays are <b>row major</b> and use <b>zero-based</b> indexing similar to that used by the C, C++ and Python languages and the ordering of arrays within netCDF files. By comparison, other common processing languages (eg., Fortran, MATLAB, R) are <b>column major</b> and use <b>one-based </b>indexing. [Fortran can change to a user defined index range: x(-12:37) ]</div><div><br></div><div>===> From the Mini-Language Manual<br></div><div><br>Section 7.7: NCL/Fortran array mapping<br><br>In Fortran, the leftmost array dimension varies fastest while in NCL the rightmost array dimension varies fastest. Sometimes this causes confusion. Rarely is reordering an array required when invoking a Fortran subroutine from an NCL script. Thus, even though the array dimension names appear in reverse order the individual array elements directly map. <span style="color:rgb(0,0,255)"><b>The rule “fastest varying dimension in one language map to fastest varying dimension in another language” applies here</b>.</span><br><br><br> NCL Fortran<br>x(time,lev,lat,lon) <=map=> x(lon,lat,lev,time)<br><br>Consider the following two arrays where N=2 and M=3:<br> ncl: x(N,M) <==> x(M,N) :Fortran<br> x(0,0) <==> x(1,1)<br> x(0,1) <==> x(2,1)<br> x(0,2) <==> x(3,1)<br> x(1,0) <==> x(1,2)<br> x(1,1) <==> x(2,2)<br> x(1,2) <==> x(3,2)</div></div><br><div class="gmail_quote"><div dir="ltr" class="gmail_attr">On Tue, May 21, 2019 at 4:58 AM Atsuyoshi MANDA <<a href="mailto:am@bio.mie-u.ac.jp" target="_blank">am@bio.mie-u.ac.jp</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left:1px solid rgb(204,204,204);padding-left:1ex">Hi Dennis and Rick,<br>
<br>
Thank you for your suggestions. I have learned how to use short2flt<br>
and coordinate subscripting and understand I did not use<br>
gsn_csm_contour_map() properly. These help me a lot.<br>
<br>
The script I sent yesterday is a part of my script that preprocesses<br>
the data for my Fortran program (I have deleted some redundant part of<br>
the script). The program assumes (lon, lat, time) dimensions and<br>
south-to-north direction in lat dimension. I want to analyze several<br>
SST datasets, so I want to reorder the dimensions in the OISST dataset<br>
to be consistent with other datasets.<br>
<br>
Thank you,<br>
Atsuyoshi<br>
<br>
2019年5月21日(火) 2:17 Dennis Shea <<a href="mailto:shea@ucar.edu" target="_blank">shea@ucar.edu</a>>:<br>
<br>
><br>
> I think I understand what you want to do. You use:<br>
><br>
> [A] This following uses standard subscripting (indexing):<br>
><br>
> print("sst(n,90-30,130)="+sst(n,90-30,130)+" "+lon(130)+"E "+lat(90-30)+"N")<br>
> print("sstre(n,130,90+30-1)="+sstre(n,130,90+30-1)+" "+lon(130)+"E<br>
> "+sstre&lat(90+30-1)+"N")<br>
><br>
><br>
> [B] I think you intended to use coordinate subscripting which uses the following syntax: {...}<br>
> A 'best practices' programming style is to use variables rather than hard-wiring numbers. Generally, this makes ithe intended use more clear.<br>
><br>
> LATS = 30<br>
> LATN = 90<br>
> LON = 130<br>
><br>
> SST = sst(n,{LATS:LATN},{LON})<br>
> printVarSummary(SST)<br>
><br>
> or, say<br>
> LATS = 30<br>
> LATN = 90<br>
> LONW = 110<br>
> LONE = 150<br>
><br>
> SST = sst(n,{LATS:LATN},{LONW:LONE})<br>
> printVarSummary(SST)<br>
><br>
> =================================<br>
> [1] Your file variable is:<br>
> short sst(time, lat, lon)<br>
><br>
> The coordinates are:<br>
><br>
> Coordinates:<br>
> time: [66443..80078]<br>
> lat: [89.5..-89.5] ; <=== North-to-South ordering<br>
> lon: [0.5..359.5]<br>
><br>
> [2] NCL has the short2flt function that unpacks an maintains meta data.<br>
><br>
> sst = short2flt( f->sst ) ; import and unpack the variable maintaining meta data<br>
> printVarSummary(sst)<br>
> printMinMax(sst,0)<br>
><br>
> [3] It is not necessary to explicitly read the following coordinate variables from the file. NCL imports the variable as a data structure ['object'] that contains the array values and meta data including coordinate information associated with the variable.<br>
><br>
> time = sst&time<br>
> lat = sst&lat<br>
> lon = sst&lon<br>
><br>
> [4] There are different methods for accessing subsets of a variable: classic indexing and coordinate variable indexing. See above.<br>
><br>
> [5] Generally, NCL graphics are aware of coordinate order. Hence, no reordering is necessary.<br>
><br>
> ---<br>
> [6]<br>
><br>
><br>
><br>
><br>
> On Sun, May 19, 2019 at 9:46 PM Atsuyoshi MANDA <<a href="mailto:am@bio.mie-u.ac.jp" target="_blank">am@bio.mie-u.ac.jp</a>> wrote:<br>
>><br>
>> Hi,<br>
>><br>
>> I am trying to reorder the array dimensions in the monthly mean OISST<br>
>> version 2 dataset, which was downloaded from<br>
>> <a href="ftp://ftp.cdc.noaa.gov/Datasets/noaa.oisst.v2/sst.mnmean.nc" rel="noreferrer" target="_blank">ftp://ftp.cdc.noaa.gov/Datasets/noaa.oisst.v2/sst.mnmean.nc</a>.<br>
>><br>
>> However, reordering using the named subscripting in my script does not work.<br>
>><br>
>> Please see the attached files:<br>
>> OIV2LR.sst.1982JUL.png (original data)<br>
>> OIV2LR.sstre.1982JUL.png (reordered data)<br>
>><br>
>> Any suggestions would be greatly appreciated.<br>
>><br>
>> Here is my script:<br>
>> ;=========================<br>
>> indir="./"<br>
>> infle="<a href="http://sst.mnmean.nc" rel="noreferrer" target="_blank">sst.mnmean.nc</a>"<br>
>> in=indir+"/"+infle<br>
>><br>
>> script_name = get_script_name()<br>
>> outdir="BIN_"+systemfunc("basename "+script_name+" .ncl")<br>
>><br>
>> dset="OIV2LR"<br>
>> MM=7<br>
>><br>
>> month_abbr = (/"","JAN","FEB","MAR","APR","MAY","JUN","JUL","AUG","SEP", \<br>
>> "OCT","NOV","DEC"/)<br>
>> MMM=month_abbr(MM)<br>
>><br>
>> system("mkdir -vp "+outdir)<br>
>><br>
>><br>
>> f=addfile(in, "r")<br>
>><br>
>> ;printVarSummary(f)<br>
>> ;print(f)<br>
>><br>
>> lon=f->lon<br>
>> lat=f->lat<br>
>> sst=f->sst<br>
>> time=f->time<br>
>><br>
>> utc_date = cd_calendar(time, 0)<br>
>><br>
>> year = tointeger(utc_date(:,0)) ; Convert to integer for<br>
>> month = tointeger(utc_date(:,1)) ; use sprinti<br>
>> day = tointeger(utc_date(:,2))<br>
>> hour = tointeger(utc_date(:,3))<br>
>> minute = tointeger(utc_date(:,4))<br>
>> second = utc_date(:,5)<br>
>> date_str = sprinti("%0.2iZ ", hour) + sprinti("%0.2i ", day) + \<br>
>> month_abbr(month) + " " + sprinti("%0.4i", year)<br>
>><br>
>> yyyys=1982<br>
>> yyyye=2017<br>
>><br>
>> sst_scaled=sst*sst@scale_factor + sst@add_offset<br>
>> copy_VarAtts(sst,sst_scaled)<br>
>> copy_VarCoords(sst,sst_scaled)<br>
>> printVarSummary(sst_scaled)<br>
>><br>
>> sstre=sst_scaled(time|:,lon|:,lat|:)<br>
>> copy_VarAtts(sst_scaled,sst)<br>
>> copy_VarCoords(sst_scaled,sstre)<br>
>> printVarSummary(sstre)<br>
>><br>
>><br>
>><br>
>> dim=dimsizes(year)<br>
>> nt=dim(0)<br>
>><br>
>> do n=7,7 ;0,nt-1<br>
>><br>
>> if(year(n) .ge. yyyys .and. year(n) .le. yyyye .and. month(n) .eq. MM)then<br>
>> print(n+" "+date_str(n))<br>
>><br>
>><br>
>> figdir="FIG_"+systemfunc("basename "+script_name+" .ncl")+"_"+dset<br>
>> system("mkdir -vp "+figdir)<br>
>> type="png"<br>
>><br>
>><br>
>><br>
>> figfle=dset+"."+"sstre."+year(n)+MMM+""<br>
>> fig=figdir+"/"+figfle<br>
>><br>
>> print("figfle="+figfle+"."+type)<br>
>><br>
>> wks = gsn_open_wks(type, fig)<br>
>><br>
>> res=True<br>
>> res@cnFillOn = True ; turn on color fill<br>
>> res@cnLinesOn = False ; turn off contour lines<br>
>> plot1=gsn_csm_contour_map(wks,sstre(n,:,:),res)<br>
>><br>
>><br>
>><br>
>> figfle=dset+"."+"sst."+year(n)+MMM+""<br>
>> fig=figdir+"/"+figfle<br>
>><br>
>> print("figfle="+figfle+"."+type)<br>
>><br>
>> wks = gsn_open_wks(type, fig)<br>
>><br>
>> res=True<br>
>> res@cnFillOn = True ; turn on color fill<br>
>> res@cnLinesOn = False ; turn off contour lines<br>
>> plot1=gsn_csm_contour_map(wks,sst(n,:,:),res)<br>
>><br>
>><br>
>> print("sst(n,90-30,130)="+sst(n,90-30,130)+" "+lon(130)+"E "+lat(90-30)+"N")<br>
>> print("sstre(n,130,90+30-1)="+sstre(n,130,90+30-1)+" "+lon(130)+"E<br>
>> "+sstre&lat(90+30-1)+"N")<br>
>><br>
>> end if<br>
>><br>
>> end do<br>
>> ;=========================<br>
>><br>
>> Thank you,<br>
>> Atsuyoshi<br>
>><br>
>> -<br>
>> Atsuyoshi Manda, Ph.D<br>
>> Associate Professor,<br>
>> Mie University<br>
>> 1577 Kurimamachiya-cho Tsu city, Mie 514-8507 JAPAN<br>
>> _______________________________________________<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/mailman/listinfo/ncl-talk</a><br>
</blockquote></div>