<div dir="ltr"><div>[1]<br>Why not use NCL directly?<br><br> <a href="http://www.ncl.ucar.edu/Document/Functions/Built-in/dim_sum_n.shtml">http://www.ncl.ucar.edu/Document/Functions/Built-in/dim_sum_n.shtml</a><br><br></div><div>In NCL: q(nlev, sn, ew) ; dimension numbers (0,1,2)<br><br></div><div> Q = dim_sum_n(q, 0) ; Q(sn,ew)<br></div><div> printVarSummary(Q)<br></div><div><br></div><div>If the original 'q' array has meta data, <br><br> <a href="http://www.ncl.ucar.edu/Document/Functions/Contributed/dim_sum_n_Wrap.shtml">http://www.ncl.ucar.edu/Document/Functions/Contributed/dim_sum_n_Wrap.shtml</a><br><br> Q = dim_sum_n_Wrap(q, 0) ; Q(sn,ew)<br><div> printVarSummary(Q)<br></div><div><br></div>========<br>[2]<br></div><div>Fortran: <br><br>NOTE: If the array in NCL is ordered q(nlev, sn, ew), the order in fortran is (ew, sn, nlev)<br><br>Your stub file arguments has 6 arguments: (nlev,sn,ew,t,q,sumforq)<br></div><div>Your f90 subroutine has 5 arguments: (nlev,sn,ew,q,sumforq)<br><br></div><div>I assume the the 't' is erroneous. Eliminate 't'<br> </div><div><br></div><div>The following works fine:<br><div><br>%> WRAPIT sum_q_total.stub sum_q_total.f90<br><br></div><div>where<br><br>-----------------------<br>sum_q_total.stub is a file containing<br><br>C NCLFORTSTART<br> subroutine sum_q_total(nlev,sn,ew,q,sumforq)<br> integer nlev,sn,ew<br> dimension q(ew,sn,nlev),sumforq(ew,sn)<br>C NCLEND<br><br>---------------------<br>sum_q_total.f90 is a file containing<br><br>subroutine sum_q_total(nlev,sn,ew,q,sumforq)<br> implicit none<br> integer,intent(in) ::nlev,sn,ew<br> real, intent(in) ::q(ew,sn,nlev)<br> real, intent(out) ::sumforq(ew,sn)<br> integer ::i,j,k<br> sumforq=0.<br> do k=1,nlev<br> do j=1,sn<br> do i=1,ew<br> sumforq(i,j)=sumforq(i,j)+q(i,j,k)<br> enddo<br> enddo<br> enddo<br> return<br>end subroutine sum_q_total<br><br></div></div></div><div class="gmail_extra"><br><div class="gmail_quote">On Sun, Jul 17, 2016 at 1:40 AM, 杨瑞 <span dir="ltr"><<a href="mailto:yangrui@mail.iap.ac.cn" target="_blank">yangrui@mail.iap.ac.cn</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"><pre style="background-color:rgb(255,255,255)"><i>Hi all,
</i><i>I want to call Fortran in NCL to read in data, but it shows errors on my Mac while
</i><i>run WRAPIT, would you please help me find out the reasons?</i></pre><pre style="background-color:rgb(255,255,255)"><i>Thanks !</i></pre><pre style="background-color:rgb(255,255,255)"><pre><i>error 1,while WRAPTI </i><span style="font-family:Menlo;font-size:11px"> sum_q_total</span><i>.stub </i><span style="font-family:Menlo;font-size:11px"> sum_q_total</span><i>.f90,shows:</i></pre><pre><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span><b>WRAPIT.c:133:2: </b></span><span style="color:#d53bd3"><b>warning: </b></span><span><b>implicit declaration of function 'sum_q_total_' is</b></span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span><b> invalid in C99 [-Wimplicit-function-declaration]</b></span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span> NGCALLF(sum_q_total,SUM_Q_TOTAL)(nlev,sn,ew,t,q,sumforq);</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,189,38)"><span><b> ^</b></span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span><b>/Users/yangrui/soft/ncl-6.2.1/include/ncarg/c.h:31:29: note: </b>expanded from macro</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span> 'NGCALLF'</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span>#define NGCALLF(reg,caps) reg##_</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,189,38)"><span><b> ^</b></span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span><b><scratch space>:292:1: note: </b>expanded from here</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span>sum_q_total_</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo;color:rgb(52,189,38)"><span><b>^</b></span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span>1 warning generated.</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span>COMPILING sum_q_total.f90</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span>LINKING</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span>ld: library not found for -lgfortran</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span>clang: error: linker command failed with exit code 1 (use -v to see invocation)</span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span>END WRAPIT</span></p><div><pre><i>erro2, while run ncl sum_q_total.ncl
</i><i>
</i><i> warning:Could not find Init() in external file ./getlatlon.so, file
</i><i> not loaded</i></pre><pre><i>***********fortran program**************</i></pre><pre>subroutine sum_q_total(nlev,sn,ew,q,sumforq)
implicit none
integer,intent(in) ::nlev,sn,ew
real, intent(in) ::q(ew,sn,nlev)
real, intent(out) ::sumforq(ew,sn)
integer ::i,j,k
sumforq=0.
do k=1,nlev
do j=1,sn
do i=1,ew
sumforq(i,j)=sumforq(i,j)+q(i,j,k)
enddo
enddo
enddo
return
end subroutine sum_q_total</pre><pre><i> *************************stub file************************</i></pre><pre>C NCLFORTSTART
subroutine sum_q_total(nlev,sn,ew,t,q,sumforq)
integer nlev,sn,ew
dimension t(ew,sn,nlev),q(ew,sn,nlev),sumforq(ew,sn)
C NCLEND</pre></div></pre></pre></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>