Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2026-04-09 07:49:20

0001 // name=srec_test ; gcc $name.cc -std=c++11 -lstdc++ -I.. -I/usr/local/cuda/include -o /tmp/$name && /tmp/$name
0002 
0003 
0004 #include <cassert>
0005 #include <cstdio>
0006 #include <cmath>
0007 #include <iostream>
0008 
0009 #include "srec.h"
0010 
0011 void test_polw()
0012 {
0013     assert( sizeof(srec) == sizeof(short4)*2 );
0014 
0015 
0016     float w0 = 80.f ; 
0017     float w1 = 800.f ; 
0018 
0019     float2 wd = make_float2( (w0+w1)/2.f, (w1-w0)/2.f ); 
0020 
0021     srec r ;
0022 
0023     const unsigned num = 3 ; 
0024 
0025     float4 ipolw[num] ;
0026     float4 opolw[num] ;
0027 
0028     ipolw[0] = make_float4( -1.f  , 0.f, 1.f,  w0  )  ;
0029     ipolw[1] = make_float4( -0.5f , 0.f, 0.5f, (w0+w1)/2.f )  ;
0030     ipolw[2] = make_float4( -0.1f , 0.f, 0.1f, w1  )  ;
0031 
0032     for(unsigned i=0 ; i < num ; i++)
0033     {
0034         float3& _ipol = (float3&)ipolw[i] ; 
0035         float3& _opol = (float3&)opolw[i] ; 
0036 
0037         float& _iw = ipolw[i].w ; 
0038         float& _ow = opolw[i].w ; 
0039 
0040         r.set_polarization( _ipol );
0041         r.get_polarization( _opol );
0042 
0043         r.set_wavelength( _iw, wd );
0044         r.get_wavelength( _ow, wd );
0045 
0046         std::cout << " ipolw " << ipolw[i] << " opolw " << opolw[i] << std::endl ;
0047 
0048         //std::cout << r.desc() << std::endl ; 
0049     }
0050 }
0051 
0052 
0053 void test_post()
0054 {
0055     float4 ce = make_float4( 100.f, 100.f, 100.f, 200.f ); 
0056     float2 td = make_float2( 0.f, 10.f ); 
0057 
0058     const unsigned num = 3 ; 
0059 
0060     float4 ipost[num] ; 
0061     float4 opost[num] ; 
0062 
0063     ipost[0] = make_float4( ce.x - ce.w , ce.y - ce.w, ce.z - ce.w,  td.x - td.y  ) ; 
0064     ipost[1] = make_float4( ce.x        , ce.y       , ce.z       ,  td.x         ) ; 
0065     ipost[2] = make_float4( ce.x + ce.w , ce.y + ce.w, ce.z + ce.w,  td.x + td.y  ) ; 
0066 
0067     srec r = {} ;
0068 
0069     for(unsigned i=0 ; i < num ; i++)
0070     {
0071         float3& _ipos = (float3&)ipost[i] ; 
0072         float3& _opos = (float3&)opost[i] ; 
0073 
0074         r.set_position( _ipos, ce); 
0075         r.get_position( _opos, ce); 
0076 
0077         r.set_time( ipost[i].w, td ); 
0078         r.get_time( opost[i].w, td ); 
0079 
0080         std::cout << r.desc() << std::endl ; 
0081     }
0082     
0083     for(unsigned i=0 ; i < num ; i++)
0084     {
0085         std::cout << std::setw(3) << i << " ipost " << ipost[i] << " opost " << opost[i] << std::endl; 
0086     }
0087 }
0088 
0089 
0090 void test_FLOAT2INT_RN()
0091 {
0092     for(float f=-100.f ; f <= 100.f ; f+= 10.f )
0093     {
0094         std::cout 
0095             << " f " << std::setw(10) << std::fixed << std::setprecision(3) << f
0096             << " FLOAT2INT_RN(f) "  << std::setw(5) << FLOAT2INT_RN(f)  
0097             << std::endl
0098             ; 
0099     }
0100 }
0101 
0102 
0103 int main()
0104 {
0105     //test_FLOAT2INT_RN(); 
0106     test_polw(); 
0107     //test_post(); 
0108 
0109 
0110     return 0 ; 
0111 }