473,394 Members | 1,840 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,394 software developers and data experts.

For loop not executing enough times.

25
hello,
this pgm of mine should loop codeperiod(37000 in this case) no. of times. However its doin it for just 3 times. Pls help. Also i think there is an exception arising somewer in my pgm nd i need to write a try-catch but dont know wat statements to write within tat. Somebody pls help me out.
Thanks,
prads

Expand|Select|Wrap|Line Numbers
  1.  
  2. for(loopcnt=0;loopcnt<codeperiods;loopcnt++)// what is codeperiods..37000 ???
  3.      {
  4.  
  5.     ///////////////U HAVE TO WRITE THE TRY-CATCH HERE!......... IF IM NOT WRONG......... /////////////////////////////////////////////////////////////////////  
  6.     ////////////////////////////////////////////////////////////////////////////////////  
  7.  
  8. //=========================================GUI update =========================================
  9.  /*if((loopcnt%50)==0)
  10.  throw loopcnt;
  11.             {
  12.             try
  13.             {
  14.             cout<<"tracking channel "<<channelnr<<"of "<<settings.noofchannels <<"PRN# "<<channel[channelnr].prn<<endl;
  15.             }         
  16.             catch(int expp)
  17.             {
  18.             cerr<<"Exceptional error occured...exiting..."<<endl;
  19.             exit(1);
  20.             }
  21.             }// end of if(loopcnt%50==0)    */
  22.  
  23. //==========================Read Next Block Of Data =========================================          
  24.  
  25.         codephasestep = codefreq / settings.samplingfreq;
  26.         blksize = ceil((settings.codelength-remcodephase) / codephasestep);
  27.  
  28.  
  29.         //allocate memory to the buffer
  30.         rawsignal = new char[blksize];
  31.         acq_data.read (rawsignal,blksize); 
  32.  
  33.         samplesread=acq_data.gcount();
  34.         cout<<"samplesread ="<<samplesread;
  35.         //cout.write(rawsignal,20);
  36.        // system("pause");  
  37.  
  38. // **************************LOOK HERE ************************  
  39.         //rawsignal=rawsignal transpose   /////How to do this
  40.  
  41.  
  42.         // cout<<"hi hello";
  43.  
  44. if(samplesread!=blksize)
  45.          {     
  46.               cout<<"Not able to read the specified number of samples  for tracking, exiting!"<<endl;                      
  47.            acq_data.close();
  48.             //cout.write (rawsignal,blksize);
  49.  
  50.           delete[] rawsignal;                         
  51.           exit(2);
  52.  
  53.           }
  54.  
  55. //==========================Set up all the code phase tracking information======================================= 
  56.          //Define index into early code vector         
  57. for(tcode=remcodephase-earlylatespc;tcode<=((blksize-0.99)*codephasestep+remcodephase-earlylatespc);)
  58.           {      
  59.  
  60.             tcode2=ceil(tcode)+1;
  61.       //shud i allocate memory for earlycode[] ??? earlycode[] etc not declared!!!!!
  62.             earlycode[i_ecode]=cacode[tcode2-1];     //check here later coz may be u should make it cacode[tcode2-1];                                
  63.            i_ecode+=1;
  64.            //count1+=1;
  65.             tcode=tcode+codephasestep;
  66.            }   
  67.          //Define index into late code vector                       
  68.  for(tcode=remcodephase+earlylatespc;tcode<=((blksize-0.99)*codephasestep+remcodephase+earlylatespc);)
  69.             {       
  70.  
  71.             tcode2=ceil(tcode)+1;
  72.             latecode[i_lcode]=cacode[tcode2-1];     //check here later coz may be u should make it cacode[tcode2-1];                                
  73.            i_lcode+=1;
  74.            //count2+=1;
  75.             tcode=tcode+codephasestep;
  76.              //cout<<"count2 is"<<count2;
  77.             }   
  78.            //Define index into prompt code vector 
  79.  for(tcode=remcodephase;tcode<=((blksize-0.99)*codephasestep+remcodephase);)
  80.             {
  81.  
  82.            // ptcode[i_tcode]=tcode;                                                                                          
  83.             tcode2=ceil(tcode)+1;
  84.             promptcode[i_pcode]=cacode[tcode2-1];     //check here later coz may be u should make it cacode[tcode2-1];                                
  85.            i_pcode+=1;
  86.          // count3+=1; //to check no of iterations
  87.            //i_tcode+=1;
  88.  
  89.             tcode=tcode+codephasestep;
  90.             //cout<<"tcodes are"<<tcode<<endl;
  91.             //cout<<"count3 is"<<count3;
  92.             //cout<<"hey";
  93.             }
  94. // remcodephase = (ptcode[blksize-1] + codephasestep) - 1023.0;         // taken as ptcode[] instead of tcode[]
  95.             remcodephase=tcode-1023;                                           //He wants the last term
  96.     cout<<"r is"<<remcodephase<<endl;
  97.  
  98. //========================Generate the carrier frequency to mix the signal to baseband===================================
  99.  
  100.  for(i_time=0;i_time<=blksize;i_time++)                         //blksize-1??????
  101.             {
  102.                time[i_time]= i_time/settings.samplingfreq;  // is time[] reqd???
  103.                trigarg[i_time]=((carrfreq*2*PI)*time[i_time]) + remcarrphase;
  104.  
  105.             }
  106.               //remcarrphase=trigarg[blksize]%(2*PI);
  107.              remcarrphase= trigarg[blksize]-(trigarg[blksize]/(2*PI)) *(2*PI);
  108.  
  109.             for(i_trigarg=0;i_trigarg<=blksize-1;i_trigarg++)   //blksize-1??? //changed from 0:blksize-1 to 0:blksize
  110.             {
  111.               carrcos[i_trigarg]=cos(trigarg[i_trigarg]);
  112.               carrsin[i_trigarg]=sin(trigarg[i_trigarg]);
  113.             }
  114. //======================== Generate the six standard accumulated values ===================================
  115.  
  116.  for(i_trigarg=0;i_trigarg<=blksize-1;i_trigarg++)   //blksize-1???
  117.             {
  118.  // multipying locally generated carrier and code with the incoming signal....integrate and dump
  119.             qbasebandsignal[i_trigarg]=carrcos[i_trigarg]*rawsignal[i_trigarg];      // rawsignal[]....2d ???????
  120.             ibasebandsignal[i_trigarg]=carrsin[i_trigarg]*rawsignal[i_trigarg];
  121.  
  122.             temp1[i_trigarg]=earlycode[i_trigarg]*ibasebandsignal[i_trigarg];
  123.             i_e=i_e+temp1[i_trigarg];
  124.             temp2[i_trigarg]=earlycode[i_trigarg]*qbasebandsignal[i_trigarg];
  125.             q_e=q_e+temp2[i_trigarg];
  126.             temp3[i_trigarg]=promptcode[i_trigarg]*ibasebandsignal[i_trigarg];
  127.             i_p=i_p+temp3[i_trigarg];
  128.             temp4[i_trigarg]=promptcode[i_trigarg]*qbasebandsignal[i_trigarg];
  129.             q_p=q_p+temp4[i_trigarg];
  130.             temp5[i_trigarg]=latecode[i_trigarg]*ibasebandsignal[i_trigarg];
  131.             i_l=i_l+temp5[i_trigarg];
  132.             temp6[i_trigarg]=latecode[i_trigarg]*qbasebandsignal[i_trigarg];
  133.             q_l=q_l+temp6[i_trigarg];
  134.             }             
  135.  
  136.  
  137.  
  138.        //==================  Find PLL error and update carrier NCO ==================================
  139.  
  140.           carrerror=atan((q_p/i_p)/(2*PI));
  141.           carrnco=oldcarrnco+(taucarr[1]/taucarr[0])*(carrerror-oldcarrerror)+(carrerror*(pdicarr/taucarr[0]));
  142.           oldcarrnco=carrnco;
  143.           oldcarrerror=carrerror;
  144.  
  145.           carrfreq=carrfreqbasis+carrnco;
  146.           trackresults[channelnr].carrfreq[loopcnt]=carrfreq;
  147.  
  148. //========================  Find DLL error and update code NCO ==================================
  149.  
  150.           num_codeerror=(sqrt(pow(i_e,2)+pow(q_e,2))- sqrt(pow(i_l,2)+pow(q_l,2)));
  151.           den_codeerror=(sqrt(pow(i_e,2)+pow(q_e,2))+ sqrt(pow(i_l,2)+pow(q_l,2)));             
  152.           codeerror=num_codeerror/den_codeerror;
  153.  
  154.          codenco=oldcodenco+(taucode[1]/taucode[0])*(codeerror-oldcodeerror)+(codeerror*(pdicode/taucode[0]));
  155.          oldcodenco=codenco;
  156.          oldcodeerror=codeerror;
  157.  
  158.          codefreq=settings.codefreqbasis-codenco;
  159.          trackresults[channelnr].codefreq[loopcnt]=codefreq;  
  160.  
  161. //======================== Output the above calculated values==================================
  162.  
  163. /*cout<<"remcodephase is"<<remcodephase<<endl;
  164. cout<<"remcarrphase is"<<remcarrphase<<endl;
  165. cout<<"I_E is"<<i_e<<endl;
  166. cout<<"I_P is"<<i_p<<endl;
  167. cout<<"I_L is"<<i_l<<endl;
  168. cout<<"Q_E is"<<q_e<<endl;
  169. cout<<"Q_P is"<<q_p<<endl;
  170. cout<<"Q_L is"<<q_l<<endl; 
  171. cout<<"carrfreq is"<<carrfreq<<endl; */
  172. cout<<"c is"<<codefreq<<endl;
  173.  
  174.  
  175. //========================  Record various measures to show in postprocessing ==================================          
  176.  
  177.         trackresults[channelnr].absolutesample[loopcnt]=acq_data.tellg();
  178.  
  179.         trackresults[channelnr].dlldiscr[loopcnt]=codeerror;     
  180.         trackresults[channelnr].dlldiscrfilt[loopcnt]=codenco;
  181.         trackresults[channelnr].plldiscr[loopcnt]=carrerror;     
  182.         trackresults[channelnr].plldiscrfilt[loopcnt]=carrnco;     
  183.  
  184.         trackresults[channelnr].i_e[loopcnt]=i_e;
  185.         trackresults[channelnr].i_p[loopcnt]=i_p;
  186.         trackresults[channelnr].i_l[loopcnt]=i_l;
  187.         trackresults[channelnr].q_e[loopcnt]=q_e;
  188.         trackresults[channelnr].q_p[loopcnt]=q_p;
  189.         trackresults[channelnr].q_l[loopcnt]=q_l;
  190.  
  191.         } // end of for(loopcnt)
  192.  
Nov 12 '07 #1
1 1356
ashitpro
542 Expert 512MB
Have you printed the value of "codeperiods"?
Nov 12 '07 #2

Sign in to post your reply or Sign up for a free account.

Similar topics

47
by: Mountain Bikn' Guy | last post by:
Take some standard code such as shown below. It simply loops to add up a series of terms and it produces the correct result. // sum numbers with a loop public int DoSumLooping(int iterations) {...
2
by: NeedHelp | last post by:
Our ASP.NET application receives around 90 anonymous hits/sec while Requests Executing usually stays around 15-25. This is good and our server performs well What our app does is load a remote...
5
by: Rajani | last post by:
Hello, First of all sorry for the long code. But i want to explain clearly what i am doing. For i = 0 To UBound(arrResSizes) - 1 For j = 0 To UBound(arrqty) - 1 For k = 1 To totopr Step 8...
21
by: Alo Sarv | last post by:
Hi From what I have understood from various posts in this newsgroup, writing event loops pretty much comes down to this: while (true) { handleEvents(); sleep(1); // or _sleep() or...
102
by: tom fredriksen | last post by:
Hi I was doing a simple test of the speed of a "maths" operation and when I tested it I found that removing the loop that initialises the data array for the operation caused the whole program to...
52
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible...
2
ADezii
by: ADezii | last post by:
If you are executing a code segment for a fixed number of iterations, always use a For...Next Loop instead of a Do...Loop, since it is significantly faster. Each pass through a Do...Loop that...
1
by: robin1983 | last post by:
Dear All, I got stuck in simple problem, I have a two php file one for registration form and one for to check and insert into the table. The problem is that when I get any kind error in...
3
by: Cainnech | last post by:
Hi, I'm making a script where I need a for loop to get the values out of selects and do a function on it. Except I don't know how to get those values out if there because the id of the selects are...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.