Re: calling fortran subroutine from NCL

From: Dennis Shea <shea_at_nyahnyahspammersnyahnyah>
Date: Sat Mar 30 2013 - 22:39:44 MDT

Always, *please* include a

    printVarSummary(Zter)

of the variable. I speculate that the fortran array should be

          REAL A(51,51,97)

In NCL this *same* array would be

          A(97,51,51)

On 3/30/13 10:26 PM, sangeeta maharjan wrote:
> Hi,
>
> In the last script I made some changes , I replaced Zter =
> wrf_user_getvar(f,"ter",1) of write_fil.ncl to Zter =
> wrf_user_getvar(f,"ter",-1) and respective changes to write_fil.f90
> and write_fil.stub.They are as follows.
>
> SUBROUTINE WFILE(A)
>
> IMPLICIT NONE
> REAL,DIMENSION(97,51,51),INTENT(IN)::A
> INTEGER::I,J,T
>
> OPEN(UNIT=12,FILE="STORE.TXT",STATUS="NEW",FORM="FORMATTED")
>
> DO T=1,97
> DO I=1,51
> DO J=1,51
>
> IF(T==1)THEN
> WRITE(12,'(51F15.4)')A(T,I,J)
> ELSE
> GOTO 10
> END IF
>
> END DO
> END DO
> END DO
> CLOSE(12)
> 10 STOP
> END SUBROUTINE WFILE
>
> C NCLFORTSTART
>
> SUBROUTINE WFILE(A)
> REAL A(97,51,51)
> C NCLEND
>
> external WRITE_FIL "./write_fil.so"
>
> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
> load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"
>
> begin
>
> f = addfile("/root/Desktop/TWAS/KTM_OUT/wrfout_d03_2012-04-26_00:00:00.nc",
> "r")
>
> Zter = wrf_user_getvar(f,"ter",-1)
>
> WRITE_FIL::WFILE(Zter)
> end
>
> For, [root@nepal F90]# WRAPIT write_fil.stub write_fil.f90
>
> WRAPIT Version: 120209
> COMPILING write_fil.f90
> LINKING
> END WRAPIT
>
> But for, [root@nepal F90]# ncl write_fil.ncl
>
> fatal:Number of elements of dimension (0) of argument (0) is (97) in
> function (WFILE), expected (51) elements
> fatal:["Execute.c":7556]:Execute: Error occurred at or near line 12 in
> file write_fil.ncl
>
> I would appreciate any help on it too.
>
> Sangeeta Maharjan.
>
>
>
> On 3/29/13, sangeeta maharjan <sangeetamaharjan@gmail.com> wrote:
>> Thanks Rick Brownrigg and Dennis Shea for your valued input.
>>
>> I simply replaced my stub file as per Dennis Shea and it worked well.
>>
>> Sangeeta Maharjan.
>>
>>
>>
>> On 3/29/13, Dennis Shea <shea@ucar.edu> wrote:
>>> The stub file is incorrect. Specifically, the lines
>>>
>>> REAL, DIMENSION(51,51),INTENT(IN) ::A
>>> INTEGER:I,J
>>>
>>> the
>>> REAL, DIMENSION(51,51),INTENT(IN) ::A
>>> is totally f90. This is not f77 syntax
>>>
>>> I am not quite sure what the following is :-)
>>> INTEGER:I,J
>>> It is neither f90 or f77 syntax. f90 would require ::
>>> =============================================
>>> Further, I am not sure why the INTEGER I,J is present.
>>> These are not being passed between NCL and the fortran code.
>>>
>>> The following is f77 syntax
>>>
>>> C NCLFORTSTART
>>> SUBROUTINE WFILE(A)
>>> REAL A(51,51)
>>> C NCLEND
>>>
>>>
>>> WRAPIT write_fil.stub write_fil.f90
>>>
>>> should work just fine.
>>>
>>> Good Luck
>>> D
>>>
>>>
>>>
>>>
>>>
>>> On 3/28/13 12:01 PM, Rick Brownrigg wrote:
>>>> Hi,
>>>>
>>>> I can reproduce the error locally. I've got it narrowed down as to where
>>>> it happens, but I don't know why yet. We'll look into it more.
>>>>
>>>> However, it looks like its somewhat benign, in that from the debugging
>>>> trace (-d switch to WRAPIT), *your* files get compiled without error and
>>>> a
>>>> "write_fil.so" shared-library is produced. Have you tried running your
>>>> ncl
>>>> script to process your WRF file?
>>>>
>>>> Hope that helps,
>>>> Rick
>>>>
>>>>
>>>> On Mar 28, 2013, at 2:27 AM, sangeeta maharjan
>>>> <sangeetamaharjan@gmail.com> wrote:
>>>>
>>>>> Hi all,
>>>>> I am planning to write variable of wrf output file into text file. For
>>>>> this I wrote subroutine in Fortran 90 format and ncl script too. They
>>>>> are write_fil.f90, write_fil stub and write_fil.ncl.
>>>>>
>>>>> write_fil.f90
>>>>>
>>>>> SUBROUTINE WFILE(A)
>>>>>
>>>>> IMPLICIT NONE
>>>>> REAL,DIMENSION(51,51),INTENT(IN)::A
>>>>> INTEGER::I,J
>>>>> OPEN(UNIT=12,FILE="STORE.TXT",STATUS="NEW",FORM="FORMATTED")
>>>>> WRITE(12,'(51F15.4)')((A(I,J),I=1,51),J=51,1,-1)
>>>>>
>>>>>
>>>>> END SUBROUTINE WFILE
>>>>>
>>>>>
>>>>> write_fil.stub
>>>>>
>>>>> C NCLFORTSTART
>>>>>
>>>>> SUBROUTINE WFILE(A)
>>>>> REAL, DIMENSION(51,51),INTENT(IN) ::A
>>>>> INTEGER:I,J
>>>>> C NCLEND
>>>>>
>>>>> write_fil.ncl
>>>>>
>>>>> external WRITE_FIL "./write_fil.so"
>>>>>
>>>>> load "$NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl"
>>>>> load "$NCARG_ROOT/lib/ncarg/nclscripts/wrf/WRFUserARW.ncl"
>>>>>
>>>>> begin
>>>>>
>>>>> f =
>>>>> addfile("/root/Desktop/TWAS/KTM_OUT/wrfout_d03_2012-04-26_00:00:00.nc",
>>>>> "r")
>>>>>
>>>>> Zter = wrf_user_getvar(f,"ter",1)
>>>>>
>>>>> WRITE_FIL::WFILE(Zter)
>>>>> end
>>>>>
>>>>>
>>>>> On giving command,I got
>>>>> [root@nepal WRF]# WRAPIT write_fil.stub write_fil.f90
>>>>>
>>>>> WRAPIT Version: 120209
>>>>> A syntax error occurred while parsing: ,
>>>>> COMPILING write_fil.f90
>>>>> LINKING
>>>>> END WRAPIT
>>>>>
>>>>> I would appreciate any help on this.
>>>>>
>>>>> Sangeeta Maharjan.
>>>>> _______________________________________________
>>>>> ncl-talk mailing list
>>>>> List instructions, subscriber options, unsubscribe:
>>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>
>>>> _______________________________________________
>>>> ncl-talk mailing list
>>>> List instructions, subscriber options, unsubscribe:
>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>
>>>
>>
_______________________________________________
ncl-talk mailing list
List instructions, subscriber options, unsubscribe:
http://mailman.ucar.edu/mailman/listinfo/ncl-talk
Received on Sat Mar 30 22:39:51 2013

This archive was generated by hypermail 2.1.8 : Tue Apr 02 2013 - 21:23:48 MDT