Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

C language problem - I'm getting compiling error

Status
Not open for further replies.

JoKKeR

Full Member level 2
Joined
Feb 14, 2008
Messages
130
Helped
2
Reputation
4
Reaction score
2
Trophy points
1,298
Location
Estonia
Activity points
2,281
C language problem

Hi !

Im using function(s) before declaration. That is the reason im getting compiling error.

On the other hand reason why im using such program build is, that i like to keep things logical, at least on math level ( scientific equations).


So are there any techniques how to solve a problem im having ?


Code:
#include <stdio.h>
#include <stdlib.h>
#include <math.h>

double L = 59.10; // latitude


double declination () //declination 583 539 87
{
       double d;
       d = declination(); //declination();
       double N = 0;
       
       N = 100;
       
       d = 23.45 * sin (360 / 365 * (284 + N)) ;

       return d;


    // d = declination
    //N = day number, January 1 = day 1


}

double hour_angle () // Hour angle 
{
       double Al;
       Al = altitude_angle() ;
       double L = L;
       double D;
       D = declination() ;
       double H = 0;
       double elev = 0;
       
       H = acos ( -1 * (sin (L) * sin (D) - sin (-0.8333 - 0.0347 *(sqrt (elev) ))) / (cos (L) * cos (D))) ;
       //H = cos-1[-1 * (sin (L) * sin (D) - sin (-0.8333 - 0.0347 (sqrt (elev)))) / (cos (L) * cos (D))] ;
       
       

    //Al = Solar altitude angle
    //L = Latitude (negative for Southern Hemisphere)
    //D = Declination (negative for Southern Hemisphere)
    //H = Hour angle

}

double altitude_angle () // Altidue angle 
{
       double Al = 0;
       double L = L;
       double D;
       D = declination() ;
       double H ;
       H = hour_angle() ;
       
       //sin(Al) =( cos(L) * cos(D) * cos(H)) + ( sin(L) * sin(D) ) ;
       Al =sin(( cos(L) * cos(D) * cos(H)) + ( sin(L) * sin(D) )) ;


    //Al = Solar altitude angle
    //L = Latitude (negative for Southern Hemisphere)
    //D = Declination (negative for Southern Hemisphere)
    //H = Hour angle


}

double azimuth_angle()
{
       
       double Az = 0;
       double Al;
       Al = altitude_angle() ;
       double L = L;
       double D;
       D = declination() ;
       
       
       
       //cos (Az) = (sin (Al) * sin (L) - sin (D)) / (cos (Al) * cos (L)) ;
        Az = cos((sin (Al) * sin (L) - sin (D)) / (cos (Al) * cos (L))) ;
       
       

    //Az = Solar azimuth angle
    //Al = Solar altitude angle
    //L = Latitude (negative for Southern Hemisphere)
    //D = Declination (negative for Southern Hemisphere)


}




double EOT () // Equation of time
{
       double N = 100;
       double B = 0;
       double E = 0;
       
       B = (360 * (N - 81)) / 365;
       
       E = (9.87 * sin(2*B)) - (7.53 * cos(B)) - (1.5 * sin(B));
       
       return E;
       
       //N = day number, January 1 = day 1 
}



int main()
{
 
  
  system("PAUSE");	
  return 0;
}



Thank you !

Added after 2 minutes:

BTW. The location of problem is between 2 or 3
function.

The variable Hour angle keep recurring .
 

Re: C language problem

The first function is recursive, it calls itself? A recursive function must have a termination state, I can not see one?
It gets worse!
The function 'hour_angle()' calls 'altitude_angle()' , which calls 'hour_angle()',
double recusion? And they both call the recursive function 'declination()'.
I wouldnt be surprised to see a wiff of smoke arise from the computer that tries to run this program.
 

    JoKKeR

    Points: 2
    Helpful Answer Positive Rating
Re: C language problem

concerning the order of functions use forward declaration:
Code:
#include <stdio.h> 
#include <stdlib.h> 
#include <math.h> 

// forward declaration of functions
double declination ();
double hour_angle ();
double altitude_angle ();
double azimuth_angle();
double EOT ();


double L = 59.10; // latitude 


double declination () //declination 583 539 87 
{ 
       double d; 
       d = declination(); //declination(); 
       double N = 0; 
        
       N = 100; 
        
       d = 23.45 * sin (360 / 365 * (284 + N)) ; 

       return d; 


    // d = declination 
    //N = day number, January 1 = day 1 


}

.
.
.

but it doesn't solve the problem with recursive functions that btbass mentioned...
 

    JoKKeR

    Points: 2
    Helpful Answer Positive Rating
C language problem

Thank you for really good replies !

I guess my skill level is way basic, i need to gain more experience. cmon i worked on this code for a day ... there are actually pone number in comments ;)

Ill try to re build whole thing, since i do not have much experience ... Can i have some advice how to combine many equations and link them to time resolution effect like thing.

Thank you !
 

C language problem

What is d = declination() supposed to do other than put the program into a non-terminating loop and have the stack go rampaging through program memory until you get an 'out of memory' message? Also, I hope you realize that C programs start with main(), and not the first function defined in the source code, because your main() does nothing. It is probably a good practice to give all functions in a file a forward declaration, it makes the code more readable. Or better yet, put them in a header file and #include it at the top of the file.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top