[ncl-talk] regCoef_n without y-axis intercept

Dennis Shea shea at ucar.edu
Tue Nov 1 14:33:22 MDT 2022


Buongiorni Giorgino,
I will look at your code later today [Tuesday].
However, in my previous response to which I attached two sample fortran
codes, I should have attached an NCL script which uses the shared object
[.sp] file.
It [tst_regcoefi.ncl]  is now attached.
===
[5] Create a .so file via

     %> WRAPIT regcoef_graffino.f

      will create regcoef_graffino.so

%> ncl tst_regcoef.ncl
      NCAR Command Language Version 6.5.0

(0) rcoef= 0.974561
(0) tval = 38.7429
(0) yint =15.3523


On Mon, Oct 31, 2022 at 1:04 PM Giorgio Graffino <g.graffino at tim.it> wrote:

> Hi Dennis,
>
>
> Thanks a lot for taking the time to write the scripts and the
> instructions. With your help I managed to make my version of the subroutine
> work (see attached) in my NCL script. Using the debug printing part, I
> checked that the subroutine version with the intercept gives the same
> result of regCoef_n. Now I'm trying to make the subroutine to return all
> the calculated variables (and most notably the regression coefficient), but
> I can't. Can I do that from NCL or do I have to write a separate Fortran
> script?
>
>
> Cheers,
>
> Giorgio
>
>
>
> ------ Messaggio Originale ------
> Da: shea at ucar.edu
> A: dave.allured at noaa.gov
> Cc: g.graffino at tim.it; ncl-talk at ucar.edu
> Inviato: giovedì 27 ottobre 2022 19:30
> Oggetto: Re: [ncl-talk] regCoef_n without y-axis intercept
>
> Oops. I inadvertently did not attach the fortran codes.
>
>
>
> On Thu, Oct 27, 2022 at 11:09 AM Dennis Shea <shea at ucar.edu> wrote:
>
>> This thread is a bit hard to follow for me.
>>
>> [1] re: "Now I'm thinking how to make the function to force the
>> regression to pass from origin. Any idea on how to do that?"
>> I do not know how to accommodate the additional constraint of making the
>> regression line'go through the origin.
>> Likely, googling something like "regression line through the origin" will
>> yield some information.
>>
>> [2] Make sure your modified fortran subroutine works. Initially, code and
>> test this only for one-dimension. We can do multiple dimensions later.
>> EG with the 'gfortran' compiler.
>> I took NCL's underlying fortran subroutine. I changed the source name to
>> RCGRAF/rcgraf to avoid any possible naming conflicts. I wrote a simple
>> fortran driver. Any fortran compiler will work
>>
>> %> gfortran tst_regcoef.f regcoef_graffino.f <=== compile fortran codes
>> %> ./a.out <=== execute the compiled codes
>>
>> rcoef= 0.974561453
>> tval = 38.7428589
>> yint = 15.3522949
>>
>> [3] Now, modify the "regcoef_graffino.f " to create a regression line
>> where there is no y-intercept
>>
>> [4] Repeat step [2] with your modified code.
>>
>> [5] Create a .so file via
>>
>> %> WRAPIT regcoef_graffino.f
>>
>> will create regcoef_graffino.so
>>
>> [6] Create a simple 1D test of invoking the .so file and print results
>>
>> [7] At this point, we can make a 2nd subroutine that invokes the .so file
>> multiple times.
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>>
>> If The (hidden) C interface to the f77 subroutine just loops over the
>> appropriate dimensions and returns the various results.
>>
>> ---
>> If you have 1D arrays [ X[N], Y[N] ]
>>
>>
>> On Wed, Oct 26, 2022 at 9:10 AM Dave Allured - NOAA Affiliate via
>> ncl-talk <ncl-talk at mailman.ucar.edu> wrote:
>>
>>> Giorgio, WRAPIT is capable of handling arrays correctly. I suggest you
>>> try some of the working fortran examples in the WRAPIT documentation, so
>>> that you can get familiar with WRAPIT and array arguments. Then, get the
>>> *original* regcoef_dp.f working with WRAPIT and arrays, but change the
>>> function name to prevent conflict. It might be helpful to write external
>>> standalone fortran main programs that call the fortran routines you are
>>> testing, to ensure those routines are working independently from NCL.
>>>
>>> Only after that, try interfacing your modified routine with WRAPIT.
>>> Please completely avoid regcoefW.c. It is full of internal protocol that is
>>> not related to WRAPIT and will continue to confuse you.
>>>
>>> I do not have time to analyze or debug your code and procedures. If
>>> needed, perhaps someone else is available.
>>>
>>>
>>> On Wed, Oct 26, 2022 at 3:09 AM Giorgio Graffino <g.graffino at tim.it>
>>> wrote:
>>>
>>>> Hi Dave,
>>>>
>>>> Thanks for confirming that. I'm changing the fortran subroutine Dennis
>>>> sent last week into a function, but it keeps giving me an error wherever I
>>>> try to use arrays as arguments. It only works when X and Y are scalar
>>>> numbers. I really don't understand how a linear regression fit can be found
>>>> with scalar numbers as arguments. I'm looking at the C interface to see how
>>>> to subroutine is called, but there are too many things happening in
>>>> regcoefW.c and it's difficult to understand the workflow. Can anyone please
>>>> help me understand how to make the fortran subroutine work for 1d and 2d
>>>> arrays?
>>>>
>>>> Cheers,
>>>>
>>>> Giorgio
>>>>
>>>>
>>>> ------ Messaggio Originale ------
>>>> Da: dave.allured at noaa.gov
>>>> A: g.graffino at tim.it
>>>> Cc: ncl-talk at ucar.edu
>>>> Inviato: lunedì 24 ottobre 2022 22:10
>>>> Oggetto: Re: [ncl-talk] regCoef_n without y-axis intercept
>>>>
>>>> Giorgio, you are right, regcoefW.c is an NCL internal interface routine
>>>> for regCoef_n. But it uses a different protocol than a WRAPIT interfaced
>>>> function. Just ignore regcoefW.c, and follow the WRAPIT fortran
>>>> instructions carefully, for your new function. Change the function name,
>>>> and do not attempt to replace the built-in regCoef_n function. You can
>>>> change the arguments as you like, but follow the documented WRAPIT rules.
>>>>
>>>> There are two different methods for calling external C functions:
>>>> fortran wrapper, and shared object. Please study the WRAPIT documentation
>>>> carefully.
>>>>
>>>>
>>>> On Mon, Oct 24, 2022 at 1:35 PM Giorgio Graffino via ncl-talk <
>>>> ncl-talk at mailman.ucar.edu> wrote:
>>>>
>>>>> Hello,
>>>>>
>>>>> I'm doing some modifications to the regcoef_dp.f file to consider a
>>>>> zero y-intercept, but now I don't know how to try it in a script. The
>>>>> number of arguments in the fortran subroutine is different than in
>>>>> regCoef_n, so the subroutine is probably going through some more steps,
>>>>> possibly involving this script (
>>>>> https://github.com/NCAR/ncl/blob/develop/ni/src/lib/nfp/regcoefW.c).
>>>>> Am I right?
>>>>>
>>>>> How can I incorporate both fortran and C scripts in my NCL script? I
>>>>> know I can use WRAPIT to read external fortran code, but what about C code?
>>>>>
>>>>> I need help please.
>>>>>
>>>>> Giorgio
>>>>>
>>>>>
>>>>> ------ Messaggio Originale ------
>>>>> Da: ncl-talk at mailman.ucar.edu
>>>>> A: shea at ucar.edu
>>>>> Cc: ncl-talk at ucar.edu
>>>>> Inviato: venerdì 21 ottobre 2022 13:14
>>>>> Oggetto: Re: [ncl-talk] regCoef_n without y-axis intercept
>>>>>
>>>>> Hi Dennis, Dave
>>>>>
>>>>> Thanks for sending the relevant function and for explaining how to
>>>>> access the source code. Now I'm thinking how to make the function to force
>>>>> the regression to pass from origin. Any idea on how to do that?
>>>>>
>>>>> Cheers,
>>>>>
>>>>> Giorgio
>>>>>
>>>>>
>>>>> ------ Messaggio Originale ------
>>>>> Da: shea at ucar.edu
>>>>> A: g.graffino at tim.it
>>>>> Cc: dave.allured at noaa.gov; ncl-talk at ucar.edu
>>>>> Inviato: giovedì 20 ottobre 2022 19:17
>>>>> Oggetto: Re: [ncl-talk] regCoef_n without y-axis intercept
>>>>>
>>>>> The f77 code is attached.
>>>>>
>>>>>
>>>>> On Thu, Oct 20, 2022 at 9:53 AM Giorgio Graffino via ncl-talk <
>>>>> ncl-talk at mailman.ucar.edu> wrote:
>>>>>
>>>>>> Hi Dave,
>>>>>>
>>>>>> Thanks for the advice. I looked at the examples in
>>>>>> https://www.ncl.ucar.edu/Applications/regress.shtml, especially
>>>>>> examples 2 and 4, but I couldn't find any supplementary information about
>>>>>> regCoef. I also can't find anything under
>>>>>> $NCARG_ROOT/lib/ncarg/nclscripts/csm/gsn_code.ncl and
>>>>>> $NCARG_ROOT/lib/ncarg/nclscripts/csm/contributed.ncl.
>>>>>>
>>>>>> Is NCL source code located anywhere in $NCARG_ROOT? Can anyone please
>>>>>> point me where it is?
>>>>>>
>>>>>> Cheers,
>>>>>>
>>>>>> Giorgio
>>>>>>
>>>>>>
>>>>>> ------ Messaggio Originale ------
>>>>>> Da: dave.allured at noaa.gov
>>>>>> A: g.graffino at tim.it
>>>>>> Cc: ncl-talk at ucar.edu
>>>>>> Inviato: giovedì 13 ottobre 2022 18:47
>>>>>> Oggetto: Re: [ncl-talk] regCoef_n without y-axis intercept
>>>>>>
>>>>>> Giorgio, for your second question, please see this very brief
>>>>>> description that I recently wrote, for how to search for functions in the
>>>>>> NCL source code.
>>>>>> https://mailman.ucar.edu/pipermail/ncl-talk/2022-August/018954.html
>>>>>>
>>>>>>
>>>>>> On Thu, Oct 13, 2022 at 10:38 AM Giorgio Graffino via ncl-talk <
>>>>>> ncl-talk at mailman.ucar.edu> wrote:
>>>>>>
>>>>>>> Hi NCL community,
>>>>>>>
>>>>>>> I want regCoef_n to find the regression coefficient between two
>>>>>>> arrays without y-axis intercept. Do you know how I can change the function
>>>>>>> to do that?
>>>>>>>
>>>>>>> Can you also please tell me where I can find the function? I did a
>>>>>>> grep recursive search in my $NCARG_ROOT directory but I couldn't
>>>>>>> find it.
>>>>>>>
>>>>>>> Cheers,
>>>>>>>
>>>>>>> Giorgio
>>>>>>>
>>>>>> _______________________________________________
>>> ncl-talk mailing list
>>> ncl-talk at mailman.ucar.edu
>>> List instructions, subscriber options, unsubscribe:
>>> https://mailman.ucar.edu/mailman/listinfo/ncl-talk
>>>
>>
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20221101/e778a9d4/attachment.htm>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: tst_regcoef.ncl
Type: application/octet-stream
Size: 1149 bytes
Desc: not available
URL: <https://mailman.ucar.edu/pipermail/ncl-talk/attachments/20221101/e778a9d4/attachment.obj>


More information about the ncl-talk mailing list