[ncl-talk] WRAPIT NCL fortran

Dennis Shea shea at ucar.edu
Sun Jul 17 11:45:08 MDT 2016


[1]
Why not use NCL directly?

         http://www.ncl.ucar.edu/Document/Functions/Built-in/dim_sum_n.shtml

In NCL:   q(nlev, sn, ew)        ; dimension numbers (0,1,2)

         Q = dim_sum_n(q, 0)    ; Q(sn,ew)
         printVarSummary(Q)

If the original 'q' array has meta data,


http://www.ncl.ucar.edu/Document/Functions/Contributed/dim_sum_n_Wrap.shtml

         Q = dim_sum_n_Wrap(q, 0)    ; Q(sn,ew)
         printVarSummary(Q)

========
[2]
Fortran:

NOTE: If the array in NCL is ordered q(nlev, sn, ew), the order in fortran
is (ew, sn, nlev)

Your stub file arguments has 6 arguments: (nlev,sn,ew,t,q,sumforq)
Your f90 subroutine has 5 arguments:         (nlev,sn,ew,q,sumforq)

I assume the the 't' is erroneous. Eliminate 't'

The following works fine:

%> WRAPIT sum_q_total.stub sum_q_total.f90

where

-----------------------
sum_q_total.stub is a file containing

C NCLFORTSTART
  subroutine   sum_q_total(nlev,sn,ew,q,sumforq)
  integer nlev,sn,ew
  dimension q(ew,sn,nlev),sumforq(ew,sn)
C NCLEND

---------------------
sum_q_total.f90 is a file containing

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


On Sun, Jul 17, 2016 at 1:40 AM, 杨瑞 <yangrui at mail.iap.ac.cn> wrote:

> *Hi all,
> **I want to call Fortran in NCL to read in data, but it shows errors on my Mac while
> **run WRAPIT, would you please help me find out the reasons?*
>
> *Thanks !*
>
> *error 1,while WRAPTI * sum_q_total*.stub * sum_q_total*.f90,shows:*
>
> *WRAPIT.c:133:2: **warning: **implicit declaration of function 'sum_q_total_' is*
>
> *      invalid in C99 [-Wimplicit-function-declaration]*
>
>         NGCALLF(sum_q_total,SUM_Q_TOTAL)(nlev,sn,ew,t,q,sumforq);
>
> *        ^*
>
> */Users/yangrui/soft/ncl-6.2.1/include/ncarg/c.h:31:29: note: *expanded from macro
>
>       'NGCALLF'
>
> #define NGCALLF(reg,caps)   reg##_
>
> *                            ^*
>
> *<scratch space>:292:1: note: *expanded from here
>
> sum_q_total_
>
> *^*
>
> 1 warning generated.
>
> COMPILING sum_q_total.f90
>
> LINKING
>
> ld: library not found for -lgfortran
>
> clang: error: linker command failed with exit code 1 (use -v to see invocation)
>
> END WRAPIT
>
> *erro2, while run ncl sum_q_total.ncl
> **       warning:Could not find Init() in external file ./getlatlon.so, file
> ** not loaded*
>
> ************fortran program***************
>
> 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
>
> * *************************stub file*************************
>
> 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
>
>
> _______________________________________________
> ncl-talk mailing list
> ncl-talk at ucar.edu
> List instructions, subscriber options, unsubscribe:
> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mailman.ucar.edu/pipermail/ncl-talk/attachments/20160717/e2f333bb/attachment.html 


More information about the ncl-talk mailing list