<div dir="ltr"><div><div>In short, the answer to your question is 'no! No! NO!!!'   :-)<br><br>From the NCL archives:<br><br><span class="gmail-il">The</span> general rule of array passing from one language to another is: <br><div><span class="gmail-il">The</span> fastest varying dimension of one language maps into fastest varying dimension of <span class="gmail-il">the</span> other language.<br><br></div><div>In fortran (column major), <span class="gmail-il">the</span> leftmost dimension varies fastest. <br></div><div>In NCL (row major) , <span class="gmail-il">the</span> rightmost dimension varies fastest.<br></div><div>------<br>Specifically see Section 7.7 at:<br>       <a href="http://www.ncl.ucar.edu/Document/Manuals/language_man.pdf" target="_blank">http://www.ncl.ucar.edu/<wbr>Document/Manuals/language_man.<wbr>pdf</a><br><br></div><span class="gmail-il">The</span> <span class="gmail-il">following</span> is extracted from 7.7:<br><br><div><font size="2"><span class="gmail-il">Consider</span> <span class="gmail-il">the</span> <span class="gmail-il">following</span> <span class="gmail-il">two</span> <span class="gmail-il">arrays</span> where N=2 and M=3:</font><div style="font-family:sans-serif"><font size="2">        ncl:   x(N,M)    <==>       x(M,N)   :Fortran<br><br></font></div><div style="font-family:sans-serif"><font size="2">               x(0,0)    <==>       x(1,1)</font></div><div style="font-family:sans-serif"><font size="2">               x(0,1)    <==>       x(2,1)</font></div><div style="font-family:sans-serif"><font size="2">               x(0,2)    <==>       x(3,1)<br><br></font></div><div style="font-family:sans-serif"><font size="2">               x(1,0)    <==>       x(1,2)</font></div><div style="font-family:sans-serif"><font size="2">               x(1,1)    <==>       x(2,2)</font></div><div style="font-size:18px;font-family:sans-serif"><font size="2">               x(1,2)    <==>       x(3,2)<br><br></font></div><div style="font-size:18px;font-family:sans-serif"><font size="2">Please note: <br><br><b>This means that an array in NCL:  x(N,M) needs ***NO*** reordering for fortran code dimensioned x(M,N)<span class="gmail-HOEnZb"><font color="#888888"><br><br></font></span></b></font></div><div class="gmail-yj6qo gmail-ajU"><div id="gmail-:1y4" class="gmail-ajR" tabindex="0"><b><img class="gmail-ajT" src="https://ssl.gstatic.com/ui/v1/icons/mail/images/cleardot.gif">D</b></div></div></div><br><br></div><br><br></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Fri, Dec 1, 2017 at 11:00 AM, Marston Ward <span dir="ltr"><<a href="mailto:marston.johnston@gu.se" target="_blank">marston.johnston@gu.se</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">




<div>
<div name="messageBodySection" style="font-size:14px;font-family:-apple-system,BlinkMacSystemFont,sans-serif">
Hi Mary,
<div><br>
</div>
<div>I’m running into the issue where the dimensions are switched between NCL and FORTRAN.</div>
<div>For example, when I pass a 2D variable: GBIN(NLAT,NLON) to the fortran subroutine, I have to switch the dimensions to GBIN(NLON,NLAT).</div>
<div>My question is, how do I handle a 3D array which is declared B(M,N,Z) in NCL? I suspect that Z and M switches places in the fortran script?</div>
<div>This is assuming WRAPIT can handle higher dimensions than 2. I could not find an example in the docs.</div>
<div><br>
</div>
<div>Cheers,</div>
<div>/M  </div>
</div>
<div name="messageSignatureSection" style="font-size:14px;font-family:-apple-system,BlinkMacSystemFont,sans-serif">
<br>
<p class="MsoNormal"><b><i>Marston S. Ward</i></b><br>
</p>
</div>
<div name="messageReplySection" style="font-size:14px;font-family:-apple-system,BlinkMacSystemFont,sans-serif"><span class="">
<br>
On 1 Dec 2017, 16:45 +0100, Mary Haley <<a href="mailto:haley@ucar.edu" target="_blank">haley@ucar.edu</a>>, wrote:<br>
</span><div><div class="h5"><blockquote type="cite" style="margin:5px 5px;padding-left:10px;border-left:thin solid #1abc9c">
<div dir="ltr">
<div class="gmail_default" style="font-size:small">Hi Marston,</div>
<div class="gmail_default" style="font-size:small"><br>
</div>
<div class="gmail_default" style="font-size:small">A tip: you can add the "-d" option to WRAPIT to get some really verbose output. This helped me see that it was this step that was causing the warning:</div>
<div class="gmail_default" style="font-size:small"><br>
</div>
<div class="gmail_default" style="font-size:small">
<p class="m_-5420499019220818889gmail-p1"><span class="m_-5420499019220818889gmail-s1">wrapit77 < binning_statsF90.stub > WRAPIT.c</span></p>
<p class="m_-5420499019220818889gmail-p1">I took a look at binning_statsF90.stub and saw two issues.</p>
</div>
<div class="gmail_default" style="font-size:small">[1] There are certain rules about a stub file used with WRAPIT. One is that the "C NCLFORTSTART" and "C NCLEND" lines must start in the first column:</div>
<div class="gmail_default" style="font-size:small"><br>
</div>
<div class="gmail_default" style="font-size:small">
<div class="gmail_default"><font face="monospace, monospace">C NCLFORTSTART</font></div>
<div class="gmail_default"><font face="monospace, monospace">       subroutine bin_stats(sf,nlat,nlon,<wbr>missing,tb_bins,ntb_bins,</font></div>
<div class="gmail_default"><font face="monospace, monospace">. . .</font></div>
<div class="gmail_default"><font face="monospace, monospace">C NCLEND</font></div>
<div class="gmail_default"><br>
</div>
</div>
<div class="gmail_default" style="font-size:small"><br>
</div>
<div class="gmail_default" style="font-size:small">[2] The "+" continuation character is starting in column 7. These have to be in column 6. This is a Fortran 77 rule. To fix, simply remove one space before the "+":</div>
<div class="gmail_default" style="font-size:small"><br>
</div>
<div class="gmail_default">
<div class="gmail_default"><font face="monospace, monospace">C NCLFORTSTART</font></div>
<div class="gmail_default"><font face="monospace, monospace">       subroutine bin_stats(sf,nlat,nlon,<wbr>missing,tb_bins,ntb_bins,</font></div>
<div class="gmail_default"><font face="monospace, monospace">     +     ntb_binsc,lat_bins,nlat_bins,<wbr>nlat_binsc,gbin,lsm,</font></div>
<div class="gmail_default"><font face="monospace, monospace">     + <span style="white-space:pre-wrap">
</span>    lat2d,outbin,outbin2)</font></div>
<div class="gmail_default"><font face="monospace, monospace">       integer j,tb,la,jl,jk</font></div>
<div class="gmail_default"><font face="monospace, monospace">       integer nlat_bins,ntb_bins,nlat_binsc,<wbr>ntb_binsc</font></div>
<div class="gmail_default"><font face="monospace, monospace">       integer tb_bins(ntb_bins)</font></div>
<div class="gmail_default"><font face="monospace, monospace">       integer lat_bins(nlat_bins)</font></div>
<div class="gmail_default"><font face="monospace, monospace">       integer nlat,nlon,sf</font></div>
<div class="gmail_default"><font face="monospace, monospace">       real    missing</font></div>
<div class="gmail_default"><font face="monospace, monospace">       real    gbin(nlat,nlon),lsm(nlat,nlon)<wbr>,lat2d(nlat,nlon)</font></div>
<div class="gmail_default"><font face="monospace, monospace">       real    outbin(sf,ntb_binsc),</font></div>
<div class="gmail_default"><font face="monospace, monospace">     + outbin2(sf,nlat_binsc,ntb_<wbr>binsc)</font></div>
<div class="gmail_default"><font face="monospace, monospace">C NCLEND</font></div>
<div class="gmail_default"><font face="monospace, monospace"><br>
</font></div>
<div class="gmail_default"><font face="arial, helvetica, sans-serif">--Mary</font></div>
</div>
</div>
<div class="gmail_extra"><br>
<div class="gmail_quote">On Fri, Dec 1, 2017 at 5:59 AM, Marston Ward <span dir="ltr">
<<a href="mailto:marston.johnston@gu.se" target="_blank">marston.johnston@gu.se</a>></span> wrote:<br>
<blockquote class="gmail_quote" style="margin:5px 5px;padding-left:10px;border-left:thin solid #e67e22">
<div>
<div name="messageBodySection" style="font-size:14px;font-family:-apple-system,BlinkMacSystemFont,sans-serif">
Hi,
<div><br>
</div>
<div>I’ve written a F90 routine to do some heavy calculations within NCL.</div>
<div>I’ve followed the instructions on how to write the “stub” file: <a href="https://www.ncl.ucar.edu/Document/Tools/WRAPIT.shtml#FixingCommonProblems" target="_blank">https://www.ncl.ucar.edu<wbr>/Document/Tools/WRAPIT.shtml#<wbr>FixingCommonProblems</a>, </div>
<div>how to make sure there are no stray characters in code, as well as made sure the routine compiles as a standalone.</div>
<div>However, when I run WRAPIT -in  stubfile myfile.F90 I get the following, despite that the SO file is created. I’ve not yet check the SO file but wanted to</div>
<div>check with the NCL experts with experience in F90 routines and WRAPIT.</div>
<div>My files are attached and here is the error message when compiling (which is not much to go on):<br>
</div>
<div><br>
</div>
<div>
<div>$ WRAPIT -in binning_statsF90.stub binning_stats.F90</div>
<div><br>
</div>
<div>WRAPIT Version: 120209</div>
<div>/software/apps/comp_wrapper/in<wbr>tel/ifort</div>
<div>A syntax error occurred while parsing:</div>
<div>COMPILING binning_stats.F90</div>
<div>LINKING</div>
<div>END WRAPIT</div>
<div><br>
</div>
</div>
<div>Would appreciate some thoughts on what’s going on. Just to reiterate a bit. I’ve gone through the trouble shooting part of the doc and made sure I’ve not made some mistakes that WRAPIT can’t handle, but fortran can. </div>
<div><br>
</div>
<div>/M</div>
</div>
<div name="messageSignatureSection" style="font-size:14px;font-family:-apple-system,BlinkMacSystemFont,sans-serif">
<br>
<p class="MsoNormal"><b><i>Marston S. Ward</i></b><br>
</p>
</div>
</div>
<br>
______________________________<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></div></div>
</div>

<br>______________________________<wbr>_________________<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/<wbr>mailman/listinfo/ncl-talk</a><br>
<br></blockquote></div><br></div>