[ncl-talk] Why the fortran routine (by WRAPIT) return the wrong value, even I did nothing with the returned variable?

Dennis Shea shea at ucar.edu
Tue Jan 31 10:37:41 MST 2017


The general rule of array passing from one language to another is:
The fastest varying dimension of one language maps into fastest varying
dimension of the other language.

In fortran, the leftmost dimension varies fastest.
In NCL, the rightmost dimension varies fastest.
------
Specifically see Section 7.7 at:
       http://www.ncl.ucar.edu/Document/Manuals/language_man.pdf

The following is extracted from 7.7
Consider the following two arrays where N=2 and M=3:
        ncl: x(N,M) <==> x(M,N) :Fortran

               x(0,0) <==> x(1,1)
               x(0,1) <==> x(2,1)
               x(0,2) <==> x(3,1)

               x(1,0) <==> x(1,2)
               x(1,1) <==> x(2,2)
               x(1,2) <==> x(3,2)

Please note: this mean that an array in NCL:  x(N,M) needs ***NO***
reordering for fortran code dimensioned (x(M,n)

D






On Tue, Jan 31, 2017 at 8:49 AM, Barry Lynn <barry.h.lynn at gmail.com> wrote:

> Glad to hear.  It is confusing keeping this all straight.
>
> Barry
>
> On Tue, Jan 31, 2017 at 4:56 PM, Tao Lu <hakufu.asano at gmail.com> wrote:
>
>> HI
>>
>> I find sth here, http://www.ncl.ucar.edu/Document/Tools/WRAPIT.shtml
>>
>> Array dimensioning
>>
>> For NCL arrays, the fastest-varying dimension is the rightmost, while for
>> Fortran it is the leftmost dimension. Therefore, if XA is a Fortran array
>> dimensioned idim x jdim, this array will be dimensioned jdim x idim in NCL.
>> Also, Fortran array subscripts start at 1, whereas NCL array subscripts
>> start at 0.
>>
>> I changed the dimension and it is okay now.
>>
>> Thank you
>>
>> On Tue, Jan 31, 2017 at 11:25 PM, Tao Lu <hakufu.asano at gmail.com> wrote:
>>
>>> Hi:
>>>
>>> Yes, I still got segmentation fault.
>>>
>>> On Tue, Jan 31, 2017 at 11:11 PM, Barry Lynn <barry.h.lynn at gmail.com>
>>> wrote:
>>>
>>>> Hi:
>>>>
>>>> Do you get a segmentation fault when even if you don't have any code
>>>> below the NCLEND?
>>>>
>>>> On Tue, Jan 31, 2017 at 3:11 PM, Tao Lu <hakufu.asano at gmail.com> wrote:
>>>>
>>>>> Hi Barry
>>>>>
>>>>> Thank you for your advice.
>>>>>
>>>>> I tried a simpler one.
>>>>>
>>>>> What I tried:
>>>>> *C NCLFORTSTART*
>>>>> *      subroutine dobjanlx(grid,mlon,nlat)        *
>>>>> *      implicit none*
>>>>> *      integer   mlon,nlat*
>>>>> *      double precision  grid(nlat,mlon) *
>>>>> *C NCLEND*
>>>>>
>>>>> *        integer   ml,nl*
>>>>> *        do nl=1,nlat *
>>>>> *          do ml=1,mlon *
>>>>> *             grid(nl,ml) = 1.d0*
>>>>> *          end do*
>>>>> *        end do*
>>>>>
>>>>> *      return*
>>>>> *      end*
>>>>>
>>>>> I called like this
>>>>>     grid = new((/nlat,nlon/),double)
>>>>>     grid at _FillValue = -999
>>>>>     test::dobjanlx(grid,nlon,nlat)
>>>>>
>>>>>
>>>>> But I got "Segmentation fault"
>>>>>
>>>>> On Tue, Jan 31, 2017 at 8:36 PM, Barry Lynn <barry.h.lynn at gmail.com>
>>>>> wrote:
>>>>>
>>>>>> Hi Tao:
>>>>>>
>>>>>> Could you please provide more information.
>>>>>>
>>>>>> Have you checked that the variables you are passing to your routine
>>>>>> are non-zero?  Did you double check that the array values are being passed
>>>>>> correctly?
>>>>>>
>>>>>> When I had a similar problem, I passed just a few variables to start
>>>>>> and checked that they correct, including array bounds.
>>>>>>
>>>>>> Barry
>>>>>>
>>>>>> On Tue, Jan 31, 2017 at 1:29 PM, Tao Lu <hakufu.asano at gmail.com>
>>>>>> wrote:
>>>>>>
>>>>>>> Hello ncl-talk
>>>>>>>
>>>>>>> I used a fortran subroutine by WRAPIT, but I even get value when I
>>>>>>> did nothing about the variable.
>>>>>>> Could you help see why?
>>>>>>>
>>>>>>> I attached the ncl script, fortran code and the output txt file.
>>>>>>>
>>>>>>>
>>>>>>> Thank you,
>>>>>>> Tao
>>>>>>> --
>>>>>>> ******************************************************
>>>>>>> 盧 涛 (ル タオ) 修士課程2年
>>>>>>>
>>>>>>> 〒112-8551 東京都文京区春日1-13-27
>>>>>>>
>>>>>>> 中央大学理工学研究科都市環境学専攻
>>>>>>>
>>>>>>> 河川・水文研究室(山田正教授)
>>>>>>>
>>>>>>>
>>>>>>> TEL: 03-3817-3406;   Phone: 070-2188-7509
>>>>>>> Email1: hakufu.asano at gmail.com <mail%3Amet.yamos at gmail.com>
>>>>>>> Email2: lutao at civil.chuo-u.ac.jp <mail%3Ayamoto at civil.chuo-u.ac.jp>
>>>>>>> *******************************************************
>>>>>>> ******************************************************
>>>>>>> Tao Lu    (M. Eng)
>>>>>>> Laboratory of River Engineering and Hydrology,
>>>>>>> Dept. of Civil and Environmental Engineering,
>>>>>>> Graduate School of Science and Engineering,
>>>>>>> Chuo University
>>>>>>>
>>>>>>> 1-13-27,Kasuga,Bunkyo-ku,Tokyo
>>>>>>> 112-8551, Japan
>>>>>>> TEL: 03-3817-1805;   Phone: 070-2188-7509
>>>>>>> Email1: hakufu.asano at gmail.com <mail%3Amet.yamos at gmail.com>
>>>>>>> Email2: lutao at civil.chuo-u.ac.jp <mail%3Ayamoto at civil.chuo-u.ac.jp>
>>>>>>> *****************************************************
>>>>>>>
>>>>>>> _______________________________________________
>>>>>>> ncl-talk mailing list
>>>>>>> ncl-talk at ucar.edu
>>>>>>> List instructions, subscriber options, unsubscribe:
>>>>>>> http://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>>>>>
>>>>>>>
>>>>>>
>>>>>>
>>>>>> --
>>>>>> Barry H. Lynn, Ph.D
>>>>>> Senior Lecturer,
>>>>>> The Institute of the Earth Science,
>>>>>> The Hebrew University of Jerusalem,
>>>>>> Givat Ram, Jerusalem 91904, Israel
>>>>>> Tel: 972 547 231 170
>>>>>> Fax: (972)-25662581
>>>>>>
>>>>>> C.E.O, Weather It Is, LTD
>>>>>> Weather and Climate Focus
>>>>>> http://weather-it-is.com
>>>>>> Jerusalem, Israel
>>>>>> Local: 02 930 9525
>>>>>> Cell: 054 7 231 170
>>>>>> Int-IS: x972 2 930 9525
>>>>>> US 914 432 3108 <(914)%20432-3108>
>>>>>>
>>>>>
>>>>>
>>>>>
>>>>> --
>>>>> ******************************************************
>>>>> 盧 涛 (ル タオ) 修士課程2年
>>>>>
>>>>> 〒112-8551 東京都文京区春日1-13-27
>>>>>
>>>>> 中央大学理工学研究科都市環境学専攻
>>>>>
>>>>> 河川・水文研究室(山田正教授)
>>>>>
>>>>>
>>>>> TEL: 03-3817-3406;   Phone: 070-2188-7509
>>>>> Email1: hakufu.asano at gmail.com <mail%3Amet.yamos at gmail.com>
>>>>> Email2: lutao at civil.chuo-u.ac.jp <mail%3Ayamoto at civil.chuo-u.ac.jp>
>>>>> *******************************************************
>>>>> ******************************************************
>>>>> Tao Lu    (M. Eng)
>>>>> Laboratory of River Engineering and Hydrology,
>>>>> Dept. of Civil and Environmental Engineering,
>>>>> Graduate School of Science and Engineering,
>>>>> Chuo University
>>>>>
>>>>> 1-13-27,Kasuga,Bunkyo-ku,Tokyo
>>>>> 112-8551, Japan
>>>>> TEL: 03-3817-1805;   Phone: 070-2188-7509
>>>>> Email1: hakufu.asano at gmail.com <mail%3Amet.yamos at gmail.com>
>>>>> Email2: lutao at civil.chuo-u.ac.jp <mail%3Ayamoto at civil.chuo-u.ac.jp>
>>>>> *****************************************************
>>>>>
>>>>
>>>>
>>>>
>>>> --
>>>> Barry H. Lynn, Ph.D
>>>> Senior Lecturer,
>>>> The Institute of the Earth Science,
>>>> The Hebrew University of Jerusalem,
>>>> Givat Ram, Jerusalem 91904, Israel
>>>> Tel: 972 547 231 170
>>>> Fax: (972)-25662581
>>>>
>>>> C.E.O, Weather It Is, LTD
>>>> Weather and Climate Focus
>>>> http://weather-it-is.com
>>>> Jerusalem, Israel
>>>> Local: 02 930 9525
>>>> Cell: 054 7 231 170
>>>> Int-IS: x972 2 930 9525
>>>> US 914 432 3108 <(914)%20432-3108>
>>>>
>>>
>>>
>>>
>>> --
>>> ******************************************************
>>> 盧 涛 (ル タオ) 修士課程2年
>>>
>>> 〒112-8551 東京都文京区春日1-13-27
>>>
>>> 中央大学理工学研究科都市環境学専攻
>>>
>>> 河川・水文研究室(山田正教授)
>>>
>>>
>>> TEL: 03-3817-3406;   Phone: 070-2188-7509
>>> Email1: hakufu.asano at gmail.com <mail%3Amet.yamos at gmail.com>
>>> Email2: lutao at civil.chuo-u.ac.jp <mail%3Ayamoto at civil.chuo-u.ac.jp>
>>> *******************************************************
>>> ******************************************************
>>> Tao Lu    (M. Eng)
>>> Laboratory of River Engineering and Hydrology,
>>> Dept. of Civil and Environmental Engineering,
>>> Graduate School of Science and Engineering,
>>> Chuo University
>>>
>>> 1-13-27,Kasuga,Bunkyo-ku,Tokyo
>>> 112-8551, Japan
>>> TEL: 03-3817-1805;   Phone: 070-2188-7509
>>> Email1: hakufu.asano at gmail.com <mail%3Amet.yamos at gmail.com>
>>> Email2: lutao at civil.chuo-u.ac.jp <mail%3Ayamoto at civil.chuo-u.ac.jp>
>>> *****************************************************
>>>
>>
>>
>>
>> --
>> ******************************************************
>> 盧 涛 (ル タオ) 修士課程2年
>>
>> 〒112-8551 東京都文京区春日1-13-27
>>
>> 中央大学理工学研究科都市環境学専攻
>>
>> 河川・水文研究室(山田正教授)
>>
>>
>> TEL: 03-3817-3406;   Phone: 070-2188-7509
>> Email1: hakufu.asano at gmail.com <mail%3Amet.yamos at gmail.com>
>> Email2: lutao at civil.chuo-u.ac.jp <mail%3Ayamoto at civil.chuo-u.ac.jp>
>> *******************************************************
>> ******************************************************
>> Tao Lu    (M. Eng)
>> Laboratory of River Engineering and Hydrology,
>> Dept. of Civil and Environmental Engineering,
>> Graduate School of Science and Engineering,
>> Chuo University
>>
>> 1-13-27,Kasuga,Bunkyo-ku,Tokyo
>> 112-8551, Japan
>> TEL: 03-3817-1805;   Phone: 070-2188-7509
>> Email1: hakufu.asano at gmail.com <mail%3Amet.yamos at gmail.com>
>> Email2: lutao at civil.chuo-u.ac.jp <mail%3Ayamoto at civil.chuo-u.ac.jp>
>> *****************************************************
>>
>
>
>
> --
> Barry H. Lynn, Ph.D
> Senior Lecturer,
> The Institute of the Earth Science,
> The Hebrew University of Jerusalem,
> Givat Ram, Jerusalem 91904, Israel
> Tel: 972 547 231 170
> Fax: (972)-25662581
>
> C.E.O, Weather It Is, LTD
> Weather and Climate Focus
> http://weather-it-is.com
> Jerusalem, Israel
> Local: 02 930 9525
> Cell: 054 7 231 170
> Int-IS: x972 2 930 9525
> US 914 432 3108 <(914)%20432-3108>
>
> _______________________________________________
> 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/20170131/60ffaccf/attachment-0001.html 


More information about the ncl-talk mailing list