EPICS Controls Argonne National Laboratory

Experimental Physics and
Industrial Control System

1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  <20112012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024  Index 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  <20112012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
<== Date ==> <== Thread ==>

Subject: Re: Calculation in SNL/SEQ
From: "Kotturi, Dayle" <[email protected]>
To: "Chestnut, Ronald P." <[email protected]>
Cc: "[email protected]" <[email protected]>
Date: Tue, 10 May 2011 21:01:38 -0700
Having just learned about pVar pointer from my colleague Kukhee Kim, I can also offer that,
in addition to adding '%%#include "math.h"' and prepending lines with c function calls with '%%', 
you may also need to help the escaped c code access the SNL variables via the pVar pointer.
  
       r1=1.0;
        r2=2.0;
        %%pVar->temp=fabs(pVar->r1-pVar->r2);
        printf("fabs:  %lf\n",temp);
        %%pVar->temp=exp(pVar->r1+pVar->r2);
        printf("exp:  %lf\n", temp);  

Without the 'pVar->', you may see these errors:
error: `temp' undeclared (first use in this function)
error: `r1' undeclared (first use in this function)
error: `r2' undeclared (first use in this function)

Dayle

On May 10, 2011, at 8:26 PM, Chestnut, Ronald P. wrote:

> Dear Liuping,
> 
> You have to include the math libraries, as  you would for a simple "C" program.
> 
> If SNL doesn't parse the libraries correctly, escape them and their use with %%.
> 
> %%include math.h
> 
> 
> %%temp=fabs(r1-r2);
> 
> Ron
> 
> On May 10, 2011, at 7:35 PM, liuping wrote:
> 
> Hello,
> I need your help about the calculation in SNL/SEQ.
> In my SNL/SEQ application, I need to execute the mathematical operation: fabs() and exp().
> Here is the codes abstracted from the my application:
> %%/////////////////////
> double   temp;
>  double  err;
>  double  r1;
>  double  r2;
> 
>  ss test123{
>         state calctest
>        {
>           when(delay(2))
>           {
>                r1=1.0;
>               r2=2.0;
>                temp=fabs(r1-r2);
>                printf("fabs:  %lf\n",temp);
>                temp=exp(r1+r2);
>                printf("exp:  %lf\n", temp);
>           } state calctest
>        }
>   }
> %%//////////////////////////
> 
> The operation result is:
> fabs:  1.000000
> exp:  2287528.000000
> fabs:  1.000000
> exp:  2287528.000000
> fabs:  1.000000
> exp:  2287528.000000
> ……
> Obviously, the result of “fabs” is right, and the other is wrong. Then I check the output of compiler. There are two warning and no error (see the bold and incline words).
> .....
> make[3]: Entering directory `/home/blctrl/watercool-Mono/motorApp/OmsSrc/O.vxWorks-ppc604_long'
> converting ../sncExample.stt
> /home/blctrl/seq-2.0.11/bin/linux-x86/snc    ../sncExample.stt -o sncExample.c.tmp
> mv sncExample.c.tmp sncExample.c
> /BLC/epics/Tornado2.2/host/x86-linux/bin/ccppc -c   -D_POSIX_SOURCE       -DCPU=PPC604  -DvxWorks -include /BLC/epics/Tornado2.2/target/h/vxWorks.h  -ansi  -O3  -Wall     -mcpu=604 -mstrict-align -mlongcall    -fno-builtin  -I. -I.. -I../../../include/os/vxWorks -I../../../include -I/home/blctrl/asyn4-8/include/os/vxWorks -I/home/blctrl/asyn4-8/include -I/home/blctrl/seq-2.0.11/include/os/vxWorks -I/home/blctrl/seq-2.0.11/include -I/BLC/epics/base/include/os/vxWorks -I/BLC/epics/base/include      -I/BLC/epics/Tornado2.2/target/h  sncExample.c
> ../sncExample.stt: In function `A_test123_calctest':
> ../sncExample.stt:38: warning: implicit declaration of function `fabs'
> ../sncExample.stt:40: warning: implicit declaration of function `exp'
> perl /BLC/epics/base/bin/linux-x86/registerRecordDeviceDriver.pl ../O.Common/omsMAXv.dbd omsMAXv_registerRecordDeviceDriver > temp.cpp
> mv temp.cpp omsMAXv_registerRecordDeviceDriver.cpp
> .....
> 
> Again, I tried to do such process:
> 1)Power off the VME rack,
> 2)Change the value of r1 and r2:    r1=9.0;    r2=12.0;
> 3)make clean
> 4)make
> 5)Power on the VME rack
> 
> Sadly I saw the result was same to last test:
> fabs:  1.000000
> exp:  2287528.000000
> fabs:  1.000000
> exp:  2287528.000000
> fabs:  1.000000
> exp:  2287528.000000
> ……
> The result of “fabs” and “exp” are both wrong. Who can tell me the reason and how to get the right result?
> Any advices are appreciated!
> 
> ===================================
> 
> LIU Ping
> 
> Beamline Control Group
> Shanghai Synchrotron Radiation Facility
> Shanghai Institute of Applied Physics
> Chinese Academy of Sciences
> Zhangheng Rd 239,Pudong Dist.,
> Shanghai 201204
> China
> Tel:+86-21-33933237(Lab)
> 
> http://ssrf.sinap.ac.cn<http://ssrf.sinap.ac.cn/>
> ===================================
> 
> 
> 



Replies:
Re: Calculation in SNL/SEQ Dirk Zimoch
References:
Calculation in SNL/SEQ liuping
Re: Calculation in SNL/SEQ Chestnut, Ronald P.

Navigate by Date:
Prev: Re: Calculation in SNL/SEQ Chestnut, Ronald P.
Next: Re: Calculation in SNL/SEQ Dirk Zimoch
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  <20112012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
Navigate by Thread:
Prev: Re: Calculation in SNL/SEQ Chestnut, Ronald P.
Next: Re: Calculation in SNL/SEQ Dirk Zimoch
Index: 1994  1995  1996  1997  1998  1999  2000  2001  2002  2003  2004  2005  2006  2007  2008  2009  2010  <20112012  2013  2014  2015  2016  2017  2018  2019  2020  2021  2022  2023  2024 
ANJ, 18 Nov 2013 Valid HTML 4.01! · Home · News · About · Base · Modules · Extensions · Distributions · Download ·
· Search · EPICS V4 · IRMIS · Talk · Bugs · Documents · Links · Licensing ·