Need help - function output to form1

General help: new users, installing the Ecere SDK, using the IDE to compile and run applications.
Post Reply
richard567
Posts: 11
Joined: Sun Feb 20, 2011 3:04 pm

Need help - function output to form1

Post by richard567 »

You can read my introduction in the General section. My problem may be a mix of C and eC and the fact that I am an amateur. Please excuse me if I get some programming terminology wrong or maybe get beyond the scope of this forum.

Brief program description: Intent is to have a continually refreshing/looping program which calculates the real-time location of the sun in azimuth and altitude based on user input location, etc. and continually updating system clock time and date. Input 10 data fields plus continuously updated clock date/time. Output sun azimuth/altitude and other related data in real-time continuously updated. There is a function which calls a .c and .h file which are linked using #include. These contain the intense calculations.

I have the form set up for input/output. The function calling the .c and .h files also compiles fine. I have a clock running on the form but had to use surface.WriteTextf to get it to display. I couldn't get it into a label. Currently the calling function has fixed input within the function. The function code is located below and outside of the class Form1 : Window.

My first problem is getting the output from that calling function to display on my form so I can test it against known output. All output is believed numeric. My original intent was to get the numeric data to display in a label. Compiler Warning indicates there may be a mix of output types from the calling function. Any thoughts/help? Here are some code snippets.

Beginning of calling function:

Code: Select all

 
int Main1 (int argc, char *argv[])
//double Main1 (double argc, char *argv[])
{
    spa_data spa;  //declare the SPA structure
    int result;
    double min, sec; // was float rather than double
 
    //enter required input values into SPA structure
 
    spa.year          = 2003;
    spa.month         = 10;
 
End of calling function:

Code: Select all

 
        min = 60.0*(spa.sunset - (int)(spa.sunset));
        sec = 60.0*(min - (int)min);
        printf("Sunset:        %02d:%02d:%02d Local Time\n", (int)(spa.sunset), (int)min, (int)sec);
 
    } else printf("SPA Error Code: %d\n", result);
 
    return 0;
//    return spa.jd, spa.l, spa.b, spa.r, spa.h, spa.del_psi, spa.del_epsilon, spa.epsilon, spa.zenith, spa.azimuth, spa.incidence;
}
 
Test string declaration for test output (actual output will be coming from numeric types). This is located before class Form1 : Window which I believe makes it public? Here is code:

Code: Select all

 
char spaazimuth[] = "hello";  // declare string for testing output
 
Test output for placement on form1. This is located within OnRedraw function within class Form1 : Window. Here it is:

Code: Select all

 
//      Main1(double spa.azimuth);
//      char spaazimuth[] = "bye";
      surface.WriteTextf(300, 96, spaazimuth);
      surface.WriteTextf(300, 128, spaazimuth);
      surface.WriteTextf(300, 160, spaazimuth);
 
I left in some commented code which are some examples of different things I have tried. Thanks in advance to anybody for any help. Hope this wasn't too lengthy.
Last edited by richard567 on Thu Feb 24, 2011 9:08 pm, edited 1 time in total.
jerome
Site Admin
Posts: 608
Joined: Sat Jan 16, 2010 11:16 pm

Re: Need help - function output to form1

Post by jerome »

Dear Richard,

First off, don't be shy in posting on the forums to ask for help. That's what it's there for.
Me or someone else will be happy to help you. The forums has many categories to cover most programming topics, and if you post it in the wrong category we will simply move it to the appropriate category.

Just something to be aware of when developing Ecere GUI applications: the main event loop is provided by default by the built-in GuiApplication class (but you could still inherit from it override its Init(), Cycle() or Terminate() methods to customize it).

To have continuous updates, you will likely want to use either a Timer object (overriding DelayExpired()), or override the Cycle() method. From there, you will have to modify a property of a control (which should cause an update to automatically happen), or modify some data and call Update() yourself on your windows for it to be redrawn (Through the OnRedraw method). If you want accurate timing, you can use high resolution timers by setting the 'timerResolution' property of the GuiApplication class.

Now, you pasted a bunch of code which I can't make much sense of how you want to tie all this together.

I see a Main1(), what is that supposed to do? Was that the entry point of the program previously?
Just so you know, you can grab argc and argv from the GuiApplication class if you ever need to.

Then I see you tyring to return multiple variables from a function. You can't do that in C/eC.
The most common way of returning multiple values from functions is to pass pointers to variables to
the function, and then you can set the values from inside the functions.

e.g.:

Code: Select all

void Divide(int a, int b, int * result, int * modulo) 
{
   *result = a / b;
   *modulo = a % b;
}
 
void Test()
{
   int a = 5, b = 3;
   int r, m;
   Divide(a, b, &r, &m);
}
Another way would be to pass a pointer to a single structure, which holds all of the information to return. For eC 'structs', they are automatically passed by reference (e.g. as a pointer), so you wouldn't need to use the &, * and -> operators.

e.g.:

Code: Select all

struct DivisionResult
{
   int result;
   int modulo;
};
 
void Divide(int a, int b, DivisionResult result)
{
   result.result = a / b;
   result.modulo = a % b;
}
 
void Test()
{
   int a = 5, b = 3;
   DivisionResult result;
   Divide(a, b, result);
}
Now if the module where that code is happens to be in eC, you could also pass in the form in which the labels or values would be updated directly.

To use labels, you will need to convert the values to strings first. You can do that with PrintString(), but beware the string returned by PrintString() needs to be deleted after you set it.
e.g.

Code: Select all

int a = 5, b = 3;
String s = PrintString(a, " / ", b, " = ", a / b);
form1.label1.text = s;
delete s;
An alternative is to use PrintStringBuf() which takes an already allocated string (e.g. a static char array, like 'char s[256];') and the maximum size of that array.

Another thing you can do is to use the SavingDataBox control, which can adapt to various data types, and you can then use ints or doubles directly. See this thread for more info about that.

Just a hint when you paste code on our forums you can use [ code=eC ] to get proper syntax highlighting.

I hope this helps! Don't hesitate to ask if you need further clarifications.

Best regards,

Jerome
jerome
Site Admin
Posts: 608
Joined: Sat Jan 16, 2010 11:16 pm

Re: Need help - function output to form1

Post by jerome »

Ah just something I forgot to mention.

You'll find that eC will give you syntax errors whenever you put declarations after statements in a block, as was the case in C89.

e.g. this will give you a syntax error:

Code: Select all

int a = 5, b = 3, result, modulo;
Divide(a, b, &result, &modulo);
int c = 10;
but this will be ok:

Code: Select all

int a = 5, b = 3, result, modulo;
int c = 10;
Divide(a, b, &result, &modulo);
It is mentioned in the Ecere Tao of Programming, but it's something to keep in mind as the compiler error messages regarding this at the moment are not very explanatory.
richard567
Posts: 11
Joined: Sun Feb 20, 2011 3:04 pm

Re: Need help - function output to form1

Post by richard567 »

Thanks very much Jerome.

I had a better reply, but by the time I finished it I had timed out on the forum and lost the message because I didn't copy or save it before posting. I'll keep this one shorter.

I've got more studying to do but you have pointed me in the right direction(s). My head is spinning but I have read bits and pieces on many of the items/suggestions you posted. I will follow those closer as time allows.

If you are interested in most of the computing end of the source code, it can be downloaded from this link (3 files):

http://www.nrel.gov/midc/spa/

These are free for personal use from the US National Renewable Energy Laboratory (NREL). The spa_tester.c code is the entire code in my Main1(...) function and used to tie into the spa.c and spa.h files. The later two files were linked into my program using #include.

Anyhow, thanks again. You will likely be hearing back from me as time allows.
jerome
Site Admin
Posts: 608
Joined: Sat Jan 16, 2010 11:16 pm

Re: Need help - function output to form1

Post by jerome »

Sorry about the timeout Richard.

I suggest you just take the 'content' inside the main() function of spa_tester, and use it wherever it is required. This way you don't have to worry about returning things outside a function.

Just set up the 'spa' structure directly where you want to use it, call spa_calculate, and then set the values of text boxes or labels from the values computed in 'spa'.

Let me know if you want me to give you sample code to do that, that should be simple enough.

Regards,

Jerome
richard567
Posts: 11
Joined: Sun Feb 20, 2011 3:04 pm

Re: Need help - function output to form1

Post by richard567 »

No problem about the timeout. It's happened before elsewhere more than once and I should have known to copy before I pressed Submit.

I did try moving the function once inside the OnRefresh brackets. I don't remember the results because I have been trying so many different things.

What I will do is read very carefully everything from all your replies, do some more research and then maybe I can zoom in further where I most need help. If you also want to post some suggested code at your convenience, that would be great also. Maybe that will set off a light in my brain. I have to be careful what I do with code inside the current Main1() because that code is tied to the spa.c and spa.h code (although I can reset all to original from my master copies if needed), much of which is way to complex for me at his point.

I have to figure out what I am calling "looping" that you mentioned and once I better understand that, I may better understand exactly where to place the Main() function. Part of my problem is I don't know in detail how certain parts/functions/methods/#define/struct/etc/etc/etc work in detail. I'm learning bits as I go. All in good time. Nothing better than hands on.

What you posted so far will help me focus better where I need to focus for this project.
richard567
Posts: 11
Joined: Sun Feb 20, 2011 3:04 pm

Re: Need help - function output to form1

Post by richard567 »

Oh ... I also wanted to say that I was used to using the MS VB 2010 and MS C++ 2010 timer which I think work different from straight C, eC or C++. With VB 2010, I just put all real-time related input/output within the timer brackets in the proper order of course and all would continually input/recalculate/output. I just need to read your comments and study further. Once I have that concept, I will be in better shape.

Thanks again Jerome.
richard567
Posts: 11
Joined: Sun Feb 20, 2011 3:04 pm

Re: Need help - function output to form1

Post by richard567 »

Hi Jerome,

I am making progress but have one problem and one question following the attached code. Following code is entire program so far. This compiles and works fine when including the spa.c and spa.h files. If the entire code is too much, let me know and I can change it.

Code: Select all

 
import "ecere"
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>  // macro - access arguments within called function
// See "The C Book" - Chapter 9.9
#include <setjmp.h>  // goto from one function to another
// See "The C Book" - Chapter 9.7
#include "spa.h"
#include "spa.c"
 
// ------------------------------------------------------------
 
// using Namespace ecere::gui::controls;
// using Namespace Main1;
 
// Watch capitalization for function names / Main () / not main ()
 
// ------------------------------------------------------------
 
char spaazimuth[] = "hello";  // declare string for testing output
 
double return12 = 123.456712;
double return13 = 123.456713;
double return14 = 123.456714;
double return15 = 123.456715;
double return16 = 123.456716;
double return17 = 123.456717;
double return18 = 123.456718;
 
char result12[256]; // used in PrintBuf() output below
char result13[256]; // used in PrintBuf() output below
char result14[256]; // used in PrintBuf() output below
char result15[256]; // used in PrintBuf() output below
char result16[256]; // used in PrintBuf() output below
char result17[256]; // used in PrintBuf() output below
char result18[256]; // used in PrintBuf() output below
 
double zzz3;
char sss3[];
 
// ------------------------------------------------------------
 
class Form1 : Window
{
   text = "Solar Position 1.0 - EC";
   background = lightYellow;
   borderStyle = fixedBevel;
   hasMinimize = true;
   hasClose = true;
   menu = {  };
   font = { "Tahoma", 8 };
   size = { 488, 412 };
   anchor = { horz = 1, vert = -57 };
   showInTaskBar = true;
 
 
   //opacity = 100;
   //moveable = true;
   //alphaBlend = false;
   //stayOnTop = false;
 
   Label label11 { this, position = { 304, 64 } };
   Label label12 { this, text = "label12", position = { 300, 96 } };
   Label label13 { this, text = "label13", position = { 300, 128 } };
   Label label14 { this, text = "label14", position = { 300, 160 } };
   Label label15 { this, text = "label15", position = { 300, 192 } };
   Label label16 { this, text = "label16", position = { 300, 224 } };
   Label label17 { this, text = "label17", position = { 300, 256 } };
   Label label18 { this, text = "label18", position = { 300, 288 } };
   Label label19 { this, text = "System Time", position = { 384, 64 } };
   Label label20 { this, text = "Altitude", position = { 384, 96 } };
   Label label21 { this, text = "Azimuth", position = { 384, 128 } };
   Label label22 { this, text = "Azimuth 180", position = { 384, 160 } };
   Label label23 { this, text = "Incidence", position = { 384, 192 } };
   Label label24 { this, text = "Sun Transit", position = { 384, 224 } };
   Label label25 { this, text = "Sunrise", position = { 384, 256 } };
   Label label26 { this, text = "Sunset", position = { 384, 288 } };
   Label label2 { this, text = "Time Zone (-12 to +12)", position = { 108, 96 } };
   Label label3 { this, text = "Longitude (-180 to +180)", position = { 108, 128 } };
   Label label4 { this, text = "Latitude (-90 to +90)", position = { 108, 160 } };
   Label label5 { this, text = "Elevation (-10000 to +65000)", position = { 108, 192 } };
   Label label6 { this, text = "Pressure (0 to +5000)", position = { 108, 224 } };
   Label label7 { this, text = "Temperature (-273 to +6000)", position = { 108, 256 } };
   Label label8 { this, text = "Slope (-360 to +360)", position = { 108, 288 } };
   Label label9 { this, text = "Azm Rotation (-360 to + 360)", position = { 108, 320 } };
   Label label10 { this, text = "Refraction (-5 to +5)", position = { 108, 352 } };
   EditBox editBox8 { this, text = "editBox8", position = { 20, 286 }, contents = "0.00" };
   EditBox editBox9 { this, text = "editBox9", position = { 20, 318 }, true, contents = "0.000" };
   EditBox editBox10 { this, text = "editBox10", position = { 20, 350 }, true, contents = "0.5667" };
   Button button1 { this, text = "Program Default", position = { 20, 16 } };
   Button button2 { this, text = "Config Default", position = { 120, 16 } };
   Button button3 { this, text = "Start", size = { 44, 21 }, position = { 276, 16 } };
   Button button4 { this, text = "Stop", size = { 44, 21 }, position = { 330, 16 } };
   Button button5 { this, text = "Exit", size = { 44, 21 }, position = { 412, 16 } };
   Label label1 { this, text = "Delta (-8000 to +8000)", position = { 108, 64 } };
   EditBox editBox1 { this, text = "editBox1", position = { 20, 62 }, true, textVertScroll = true, contents = "32.184" };
   EditBox editBox2 { this, text = "editBox2", position = { 20, 94 }, contents = "-6" };
   EditBox editBox3 { this, text = "editBox3", position = { 20, 126 }, contents = "-88.2433" };
   EditBox editBox4 { this, text = "editBox4", position = { 20, 158 }, contents = "42.21139" };
   EditBox editBox5 { this, text = "editBox5", position = { 20, 190 }, contents = "246.888" };
   EditBox editBox6 { this, text = "editBox6", position = { 20, 222 }, contents = "1015.00" };
   EditBox editBox7 { this, text = "editBox7", position = { 20, 254 }, contents = "4.444" };
 
// 90 -------------------------------------------------------------
 
 
 
// -------------------------------------------------------------
// START TIMER
   Timer timer
   {
      userData = this, started = true, delay = 0.1;
 
      bool DelayExpired()
      {
         Update(null);
         return true;
      }
   };
 
// 107 --------------------
 
 
 
// --------------------
 
 
 
// ---------------------
 
//String Get1 (double zzz3)
//{
//sss3 = PrintString(zzz3);
//return sss3;
//}
 
// ---------------------
 
 
 
// ---------------------
 
   bool OnKeyDown(Key key, unichar ch)
   {
      if(key == escape) Destroy(0);
      return true;
   }
 
// ----------------------
 
//      form1.label14.text = "54321";
 
   void OnRedraw(Surface surface)
   {
      //double answer1;
 
      DateTime time;
//      surface.Clear(colorBuffer);
      time.GetLocalTime();
//      surface.SetForeground({ 128, darkGray });
//      surface.WriteTextf(0,0, "%02d:%02d:%02d", 
//         time.hour, time.minute, time.second);
      surface.SetForeground({ 192, teal });
      surface.WriteTextf(300, 64, "%02d:%02d:%02d", 
         time.hour, time.minute, time.second);
 
      //label11.text = time.second;
 
// -----------------------
 
 
 
// ------------------------
 
      return12 = Main12();
      // Zenith = 0 straight up and 90 at horizon
      // This IF corrects Zenith to Altitude
      // Altitude = 0 at horizon / + above horizon / - below horizon
      if (return12 > 90)
      {
      return12 = 0 - (return12 - 90);
      }
      else
      {
      return12 = 90 - return12;
      }
      return12 = round(return12 * 1000) / 1000;
 
      return13 = Main13();
      return13 = round(return13 * 1000) / 1000;
//      return14 = Main14();
//      return15 = Main15();
//      return16 = Main16();
//      return17 = Main17();
//      return18 = Main18();
 
// ------------------------
 
      PrintBuf(result12, sizeof(return12), return12); // label12
      PrintBuf(result13, sizeof(return13), return13); // label13
//      PrintBuf(result14, sizeof(return14), return14); // label14
//      PrintBuf(result15, sizeof(return15), return15); // label15
//      PrintBuf(result16, sizeof(return16), return16); // label16
//      PrintBuf(result17, sizeof(return17), return17); // label17
//      PrintBuf(result18, sizeof(return18), return18); // label18
 
// ------------------------
 
//      surface.WriteTextf(300, 96, spaazimuth); // label12
      form1.label12.text = result12;
 
//      surface.WriteTextf(300, 128, spaazimuth); // label13
      form1.label13.text = result13;
 
//      surface.WriteTextf(300, 160, spaazimuth); // label14
      form1.label14.text = "54321";  // This works as is
 
//      surface.WriteTextf(300, 192, spaazimuth); // label15
      form1.label15.text = spaazimuth;
 
//      surface.WriteTextf(300, 224, spaazimuth); // label16
      form1.label16.text = spaazimuth;
 
//      surface.WriteTextf(300, 256, spaazimuth); // label17
      form1.label17.text = spaazimuth;
 
//      surface.WriteTextf(300, 288, spaazimuth); // label18
      form1.label18.text = spaazimuth;
 
   }
 
//Test from Ecere
 
//void PrintTest()
//{
//int a = 5, b = 3;
//char sss3[] = "12345";
//double zzz3 = 25.03195762;
//String sss3 = PrintString(zzz3, " / ");
//form1.label14.text = "54321";
//delete sss3;
//return 0;
//}
 
//-------------------------
}  // End class Form1 : Window --------------------------
 
// ============================================================= 
 
Form1 form1 {};  // End Form1 form1 --------------------------------
 
 
 
/*
void Main2 ()
{ 
//return 0;
}
*/
 
 
 
/*
// SAMPLE - requires iostream in this example
class A{
	static void F(){
		std::cout <<"A::F()"<<std::endl;
	}
};
 
class B{
	static void F(){
		A::F();
	}
};
 
int Main4(){
	B::F();
	return 0;
}
*/
 
 
//Test from Ecere
 
//void PrintTest()
//{
//int a = 5, b = 3;
//char sss3[] = "12345";
//double zzz3 = 25.03195762;
//String sss3 = PrintString(zzz3, " / ");
//Form1::form1::Label::label15.text = "54322";
//delete sss3;
//return 0;
//}
 
// ============================================================
 
double Main12 ()
{
    spa_data spa;  //declare the SPA structure
    int result;
    double min, sec; // was float rather than double
 
    //enter required input values into SPA structure
 
    DateTime time;
    time.GetLocalTime();
 
/*
    spa.year          = 2003;
    spa.month         = 10;
    spa.day           = 17;
    spa.hour          = 12;
    spa.minute        = 30;
    spa.second        = 30;
*/
 
    spa.year          = time.year;
    spa.month         = 2;
//    spa.month         = time.month;
    spa.day           = time.day;
    spa.hour          = time.hour;
    spa.minute        = time.minute;
    spa.second        = time.second;
 
/*
    spa.timezone      = -7.0;
    spa.delta_t       = 67;
    spa.longitude     = -105.1786;
    spa.latitude      = 39.742476;
    spa.elevation     = 1830.14;
    spa.pressure      = 820;
    spa.temperature   = 11;
    spa.slope         = 30;
    spa.azm_rotation  = -10;
    spa.atmos_refract = 0.5667;
    spa.function      = SPA_ALL;
*/
 
    spa.timezone      = -6.0;
    spa.delta_t       = 67;
    spa.longitude     = -88.24333;
    spa.latitude      = 42.21139;
    spa.elevation     = 246.888;
    spa.pressure      = 1010;
    spa.temperature   = -1;
    spa.slope         = 0;
    spa.azm_rotation  = 0;
    spa.atmos_refract = 0.5667;
    spa.function      = SPA_ALL;
 
    //call the SPA calculate function and pass the SPA structure
 
    result = spa_calculate(&spa);
 
    if (result == 0)  //check for SPA errors
    {
        //display the results inside the SPA structure
 
        printf("Julian Day:    %.6f\n",spa.jd); // float
        printf("L:             %.6e degrees\n",spa.l); //scientific
        printf("B:             %.6e degrees\n",spa.b);
        printf("R:             %.6f AU\n",spa.r);
        printf("H:             %.6f degrees\n",spa.h);
        printf("Delta Psi:     %.6e degrees\n",spa.del_psi);
        printf("Delta Epsilon: %.6e degrees\n",spa.del_epsilon);
        printf("Epsilon:       %.6f degrees\n",spa.epsilon);
        printf("Zenith:        %.6f degrees\n",spa.zenith);
        printf("Azimuth:       %.6f degrees\n",spa.azimuth);
        printf("Incidence:     %.6f degrees\n",spa.incidence);
 
//        form1.surface.WriteTextf(300, 128, spa.azimuth);
 
        min = 60.0*(spa.sunrise - (int)(spa.sunrise));
        sec = 60.0*(min - (int)min);
        printf("Sunrise:       %02d:%02d:%02d Local Time\n", (int)(spa.sunrise), (int)min, (int)sec);
 
        min = 60.0*(spa.sunset - (int)(spa.sunset));
        sec = 60.0*(min - (int)min);
        printf("Sunset:        %02d:%02d:%02d Local Time\n", (int)(spa.sunset), (int)min, (int)sec);
 
    } else printf("SPA Error Code: %d\n", result);
 
//    return 0;
    return spa.zenith;
}
 
// ============================================================
 
/////////////////////////////////////////////
//          SPA TESTER for SPA.C           //
//                                         //
//      Solar Position Algorithm (SPA)     //
//                   for                   //
//        Solar Radiation Application      //
//                                         //
//             August 12, 2004             //
//                                         //
//   Filename: SPA_TESTER.C                //
//                                         //
//   Afshin Michael Andreas                //
//   afshin_andreas@nrel.gov (303)384-6383 //
//                                         //
//   Measurement & Instrumentation Team    //
//   Solar Radiation Research Laboratory   //
//   National Renewable Energy Laboratory  //
//   1617 Cole Blvd, Golden, CO 80401      //
/////////////////////////////////////////////
 
/////////////////////////////////////////////
// This sample program shows how to use    //
//    the SPA.C code.                      //
/////////////////////////////////////////////
 
//#include <stdio.h>
//#include "spa.h"  //include the SPA header file
 
/*
The argc and argv values are passed into the entry point when an application is executed by the runtime (mainCRTStartup.)
argc stands for Argument Count. This variable contains the number of arguments passed into the application.
argv stands for Argument Values. This is an array of strings which contains the values passed into the application. argv[0] is always the name of the application.
 
What they basically do is allow you to use the command line parameters passed to your application. Even if you declare them in main(), you are not forced to use them, however some compilers might give you a warning for "unused variable."
*/
 
//int Main13 (int argc, char *argv[])
double Main13 ()
{
    spa_data spa;  //declare the SPA structure
    int result;
    double min, sec; // was float rather than double
 
    //enter required input values into SPA structure
 
    DateTime time;
    time.GetLocalTime();
 
/*
    spa.year          = 2003;
    spa.month         = 10;
    spa.day           = 17;
    spa.hour          = 12;
    spa.minute        = 30;
    spa.second        = 30;
*/
 
    spa.year          = time.year;
    spa.month         = 2;
//    spa.month         = time.month;
    spa.day           = time.day;
    spa.hour          = time.hour;
    spa.minute        = time.minute;
    spa.second        = time.second;
 
/*
    spa.timezone      = -7.0;
    spa.delta_t       = 67;
    spa.longitude     = -105.1786;
    spa.latitude      = 39.742476;
    spa.elevation     = 1830.14;
    spa.pressure      = 820;
    spa.temperature   = 11;
    spa.slope         = 30;
    spa.azm_rotation  = -10;
    spa.atmos_refract = 0.5667;
    spa.function      = SPA_ALL;
*/
 
    spa.timezone      = -6.0;
    spa.delta_t       = 67;
    spa.longitude     = -88.24333;
    spa.latitude      = 42.21139;
    spa.elevation     = 246.888;
    spa.pressure      = 1010;
    spa.temperature   = -1;
    spa.slope         = 0;
    spa.azm_rotation  = 0;
    spa.atmos_refract = 0.5667;
    spa.function      = SPA_ALL;
 
    //call the SPA calculate function and pass the SPA structure
 
    result = spa_calculate(&spa);
 
    if (result == 0)  //check for SPA errors
    {
        //display the results inside the SPA structure
 
        printf("Julian Day:    %.6f\n",spa.jd); // float
        printf("L:             %.6e degrees\n",spa.l); //scientific
        printf("B:             %.6e degrees\n",spa.b);
        printf("R:             %.6f AU\n",spa.r);
        printf("H:             %.6f degrees\n",spa.h);
        printf("Delta Psi:     %.6e degrees\n",spa.del_psi);
        printf("Delta Epsilon: %.6e degrees\n",spa.del_epsilon);
        printf("Epsilon:       %.6f degrees\n",spa.epsilon);
        printf("Zenith:        %.6f degrees\n",spa.zenith);
        printf("Azimuth:       %.6f degrees\n",spa.azimuth);
        printf("Incidence:     %.6f degrees\n",spa.incidence);
 
//        form1.surface.WriteTextf(300, 128, spa.azimuth);
 
        min = 60.0*(spa.sunrise - (int)(spa.sunrise));
        sec = 60.0*(min - (int)min);
        printf("Sunrise:       %02d:%02d:%02d Local Time\n", (int)(spa.sunrise), (int)min, (int)sec);
 
        min = 60.0*(spa.sunset - (int)(spa.sunset));
        sec = 60.0*(min - (int)min);
        printf("Sunset:        %02d:%02d:%02d Local Time\n", (int)(spa.sunset), (int)min, (int)sec);
 
    } else printf("SPA Error Code: %d\n", result);
 
//    return 0;
    return spa.azimuth;
//    return time.month;
}
 
/////////////////////////////////////////////
// The output of this program should be:
//
//Julian Day:    2452930.312847
//L:             2.401826e+01 degrees
//B:             -1.011219e-04 degrees
//R:             0.996542 AU
//H:             11.105902 degrees
//Delta Psi:     -3.998404e-03 degrees
//Delta Epsilon: 1.666568e-03 degrees
//Epsilon:       23.440465 degrees
//Zenith:        50.111622 degrees
//Azimuth:       194.340241 degrees
//Incidence:     25.187000 degrees
//Sunrise:       06:12:43 Local Time
//Sunset:        17:20:19 Local Time
//
/////////////////////////////////////////////
 
///////// IGNORE ALL AFTER THIS LINE ///////////// 
 
Problem 1: About 1/2 to 2/3 down in the code under Main12() and Main13() I am trying to retrieve real-time date and time. This is returning a value of 1 for the time.month variable which I assume is the value of an error as we are currently in February. While testing the various values for time.year, time.month, time.day, time.hour, time.minute and time.second, I received an error or warning message during compile regarding time.month with some kind of conflict with Ecere. I currently have a temporary fix built into my code for testing, however, this will be a problem with any final code if I can't determine where the conflict is. If I can re-create the error message, I will provide it at a later date. Any thoughts?

Question 1: I used PrintBuf() to convert my double to string for output to the window. Is there a way to format the output using this method? Example is 12.65930 displays as 12.6593 rather than 12.65930. I want to retain my trailing zero's.

EDIT: I switched to sprintf() for output. Formatting resolved. Making good progress now that my calcs display. Much of the code has been reorganized also. Still sloppy but I'll fix that near the end.

The code is a work in progress so please bear with me. The output updates once per second same as the clock which is fine with me and is coded in the OnRefresh() module. So far, the output has been tested against known output values included within the code comments under Main13() and against a similar but slightly less accurate EXE program created and compiled using QBasic while running side-by-side with this program in debug mode. Now I have to work on using the user input rather than the fixed input supplied in the code (except the real-time date/time).

Thanks in advance.
Post Reply