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.