diff --git a/RKSIM.po b/RKSIM.po new file mode 100644 index 0000000..b4b7ac6 Binary files /dev/null and b/RKSIM.po differ diff --git a/scr/DCMotor.c b/scr/DCMotor.c new file mode 100644 index 0000000..1e7196e --- /dev/null +++ b/scr/DCMotor.c @@ -0,0 +1,244 @@ +/* Copyright (C) 2013 Riccardo Greco rigreco.grc@gmail.com. +* +* This project is based on 1999-2000 Thesis work of Greco Riccardo. +* It implement an Runge Kutta 4(5)^ order integration numerical method of differential equations set +* by use of double precision floating point operation in Aztec C65 language. +* It allow to simulate different mathematical models such as: +* Resistance Capacitor electrical circuit, Direct Current electric motor, +* Alternative Current three phase induction motor. +* +* Thanks to Bill Buckels for his invaluable support: +* Aztec C compilers http://www.aztecmuseum.ca/compilers.htm +*/ +/* PROCESS MODULE */ +#include +#include +#include +#include + +#define rkfr 1.0e-3 /* RKF max resolution hrkfr); + */ + /* y3 y4 weighted average of operators 5^ order */ + y[0]=(double)(y_init[0]+(ips5[0]*r11+ips5[2]*r31+ips5[3]*r41+ips5[4]*r51)*h); + y[1]=(double)(y_init[1]+(ips5[0]*r12+ips5[2]*r32+ips5[3]*r42+ips5[4]*r52)*h); + + /* ------------------------------------------------------------------------------*/ + +} + +ovmain() +{ +char buf[20]; +/*double atof(); /* DON'T FORGET THIS */ +double x,y[2],y_init[2]; +struct data rk; + + + /* inizialization */ + cnt= (int)0.0; /* Reset counter */ + y[0] = (double)0.0; + y[1] = (double)0.0; + y_init[0]= (double)0.0; /* init value of current ia(t) (for Harmonic oscillator y_3=10.0) */ + y_init[1]= (double)0.0; /* init value of angular speed w(t) (for Harmonic oscillator y_4=10.0) */ + x=(double)0.0; /* time in simulation */ + + /* Start simulation */ + scr_clear(); + scr_curs(0,0); + puts("Pocessing..."); + + /* open and write header data to file */ + open(FILE_NAME,O_WRONLY|O_APPEND,0xC3); + write(fd,fbuf,80); + + buf[0]='\0'; /* buffers reset */ + fbuf[0]='\0'; + + /* RK main Cycle */ + while (x +#include "d2monplt.h" +/* +extern int clearhgr(); +*/ +ovmain(screenmode) +unsigned screenmode; +{ + switch(screenmode) + { + case 1: + scr_clear(); + d2hireson(); + clearhgr(911); + maintoaux(0x4000,0x4000+8191,0x4000); + break; + case 2: + d2hiresoff(); + scr_clear(); + } + return 0; +} diff --git a/scr/INDC.c b/scr/INDC.c new file mode 100644 index 0000000..b1b3666 --- /dev/null +++ b/scr/INDC.c @@ -0,0 +1,108 @@ +/* Copyright (C) 2013 Riccardo Greco rigreco.grc@gmail.com. +* +* This project is based on 1999-2000 Thesis work of Greco Riccardo. +* It implement an Runge Kutta 4(5)^ order integration numerical method of differential equations set +* by use of double precision floating point operation in Aztec C65 language. +* It allow to simulate different mathematical models such as: +* Resistance Capacitor electrical circuit, Direct Current electric motor, +* Alternative Current three phase induction motor. +* +* Thanks to Bill Buckels for his invaluable support: +* Aztec C compilers http://www.aztecmuseum.ca/compilers.htm +*/ +/* INPUT MODULE */ +#include +#include + + +/* GENERAL GLOBAL */ +extern double h,time; +extern char fbuf[80]; +extern int cnt; + +/* LOCAL GLOBAL */ +char *title = "Runge Kutta Fehlberg integration methods"; +char *title1= "DC Motor transient state simulation:"; +char *title2= "Current: [ia'(t)=(va/la)-(ra/la)*ia(t)-kf*w(t)/la]"; +char *title3= "Anglar speed: [w'(t)=(1/j)*(MM-MC)=(1/j)*(kf*ia(t)-MC)]"; +char *title4= "in Aztec C for Apple II 128k series - by Greco Riccardo - Apple ][ Forever!"; +char *title5= "Thanks to Bill Buckels for all support - http://www.aztecmuseum.ca/ "; + +char *out[3]={" DCMotor h="," ts="," cycles="}; /* always at global */ + +ovmain() +{ +char buf[20],conv[4],rev; +double atof(); /* DON'T FORGET THIS */ + +IN: /* set screen */ + #asm + jsr $c300 + #endasm + + buf[0]='\0'; /* buffers reset */ + fbuf[0]='\0'; + + /* Presentation */ + puts(title); + puts(title1); + puts(title2); + puts(title3); + puts(title4); + puts(title5); + puts(" "); + + /* Input data */ + do{ + puts("Time step integration (Def. 0.01s) h [s] -> "); + h=(double)atof(gets(buf)); + } while (h<0 || h<=0.005 || h>0.01); + + strcat(fbuf,out[0]); + strcat(fbuf,buf); + + do{ + puts("Time simulation (Def. 5) ts [s] -> "); + time=(double)atof(gets(buf)); + } while (time<0); + + strcat(fbuf,out[1]); + strcat(fbuf,buf); + + strcat(fbuf,out[2]); + ftoa((time/h),buf,0,1); /* 0 decimal like int */ + strncpy(conv,buf,4); /* save cnt to conv first 4 digit*/ + strcat(fbuf,buf); + + puts(fbuf); /* Input data Review */ + + puts("Do you want to review input data (Y/N)?"); + rev=getch(); +if (rev == 'Y' || rev == 'y') goto IN; + + /* set screen */ + scr_clear(); + scr_curs(0,0); + + /* Simulation data review */ + puts("DC Motor Default parameters set:"); + scr_curs(2,0); + puts("Number of input cycles:"); + scr_curs(2,31); + puts(conv); + puts("Input voltage E= 160.0 V"); + puts("Armor (stator) resistence ra= 9.47 Ohm"); + puts("Armor (stator) inductance la= 0.0375 Henry"); + puts("Flux gain (kf=k*flux) kf= 0.98 Wb"); + puts("Rotor inertia j= 0.011 kg*m2"); + puts("Load torque MC= 0.0 kg*m"); + + puts(""); + + puts("Press any key to start simulation..."); + getch(); + + + return 0; +} + diff --git a/MainM.c b/scr/MainM.c similarity index 94% rename from MainM.c rename to scr/MainM.c index f51592c..d06ba9d 100644 --- a/MainM.c +++ b/scr/MainM.c @@ -1,12 +1,13 @@ /* Copyright (C) 2013 Riccardo Greco rigreco.grc@gmail.com. * -* This work is based on 1999-2000 Thesis work of Greco Riccardo. +* This project is based on 1999-2000 Thesis work of Greco Riccardo. * It implement an Runge Kutta 4(5)^ order integration numerical method of differential equations set * by use of double precision floating point operation in Aztec C65 language. * It allow to simulate different mathematical models such as: * Resistance Capacitor electrical circuit, Direct Current electric motor, * Alternative Current three phase induction motor. * +* Thanks to Bill Buckels for his invaluable support: * Aztec C compilers http://www.aztecmuseum.ca/compilers.htm */ #include diff --git a/scr/OUTDC.c b/scr/OUTDC.c new file mode 100644 index 0000000..58b3ac3 --- /dev/null +++ b/scr/OUTDC.c @@ -0,0 +1,103 @@ +/* Copyright (C) 2013 Riccardo Greco rigreco.grc@gmail.com. +* +* This project is based on 1999-2000 Thesis work of Greco Riccardo. +* It implement an Runge Kutta 4(5)^ order integration numerical method of differential equations set +* by use of double precision floating point operation in Aztec C65 language. +* It allow to simulate different mathematical models such as: +* Resistance Capacitor electrical circuit, Direct Current electric motor, +* Alternative Current three phase induction motor. +* +* Thanks to Bill Buckels for his invaluable support: +* Aztec C compilers http://www.aztecmuseum.ca/compilers.htm +*/ +#include +#include +#include +#include "d2monplt.h" + +/* GENERAL GLOBAL */ +extern double h,keep; +extern char fbuf[80]; +extern int cnt,fd; /* x FILE LOW lEVEL DON'T FORGET THIS */ +extern struct data { + char v[20]; + char i[20]; + }; + +/* LOCAL GLOBAL */ +char *FILE_NAME="dcrk"; + +ovmain() +{ + +double nc,ia,w,xscale,iscale,wscale; +int plotx,ploty,plotey,ic,px,py,; +struct data rk; +double atof(); /* DON'T FORGET THIS */ +char tx[4]; + /* inizialization */ + + px=(int)0.0; + py=(int)0.0; + ic=(int)0.0; + xscale=(double)100.0; /* set x scale plot */ + iscale=(double)1.0; /* set y (ia(t)) scale plot */ + wscale=(double)0.5; /* set y (w(t)) scale plot */ + nc=(double)0.0; + + + /* GRAPHICS SECTION */ + + /* Axes */ + for (px=0,py=96;px<=560;++px) + { + d2monoplot(px,py,py,1); + } /*Axis X */ + + + /* for (px=0,py=0;py<=192;++py) + { + d2monoplot(px,py,py,1); + } /* Axis Y */ + + + /* labels */ + monoplots("t=",505,36,1,'M'); + monoplots("ia(t)=",25,0,1,'M'); + monoplots("w(t)=",25,10,1,'M'); + + /* read first recort (header) for increment file pointr */ + open(FILE_NAME,O_RDONLY,0xC3); + read(fd,fbuf,80); + + /* Main Plot */ + for (ic=0;ic +#include +#define micro 1.0e-6 +#define kilo 1.0e+3 + +/* GENERAL GLOBAL */ +extern double h,time,time2,sur,r,c,tau,yinit; +extern char fbuf[80]; +extern int cnt,z; + +/* LOCAL GLOBAL */ +char *title = "Runge Kutta and Runge Kutta Fehlberg integration methods"; +char *title1= "R-C circuit transient state simulation:"; +char *title2= "charge: [vc'(t)=(1/RC)*(E-vc(t))]- [i(t)=(E-vc(t))/R]"; +char *title3= "discharge: [vc'(t)=(1/RC)*(-vc(t))] - [i(t)=(-vc(t))/R]"; +char *title4= "in Aztec C for Apple II 128k series - by Greco Riccardo - Apple ][ Forever!"; +char *title5= "Thanks to Bill Buckels for all support - http://www.aztecmuseum.ca/ "; + +char *out[8]={" RCCircuit h="," ts="," td="," E="," R="," C="," vc(0)="," cycles="}; /* always at global */ + +ovmain() +{ +char buf[20],conv[4],rev; +double atof(); /* DON'T FORGET THIS */ + +IN: /* set screen */ + #asm + jsr $c300 + #endasm + + buf[0]='\0'; /* buffers reset */ + fbuf[0]='\0'; + + /* Presentation */ + puts(title); + puts(title1); + puts(title2); + puts(title3); + puts(title4); + puts(title5); + puts(" "); + + /* Input data */ + do{ + puts("Time step integration (Def. 0.01s) h [s] -> "); + h=(double)atof(gets(buf)); + } while (h<0 || h<=0.005); + + strcat(fbuf,out[0]); + strcat(fbuf,buf); + + do{ + puts("Time simulation charge (Def. 5) ts [s] -> "); + time=(double)atof(gets(buf)); + } while (time<0); + + strcat(fbuf,out[1]); + strcat(fbuf,buf); + + do{ + puts("Istant time to start discharge (Def. 2.5) (td<=ts) td [s] ->"); /* td istant time to discarge */ + time2=(double)atof(gets(buf)); + } while (time2<0 || time2>time); + + strcat(fbuf,out[2]); + strcat(fbuf,buf); + + puts("Input Voltage value (Def. 50) E [Volt] -> "); /* Input step voltage E [V] */ + sur=(double)atof(gets(buf)); + + strcat(fbuf,out[3]); + strcat(fbuf,buf); + + do{ + puts("Resistence value (Def. 10) R [KiloOhm]-> "); /* Resistence R */ + r=(double)atof(gets(buf)); + } while (r<=0); + + r=(double)(r*(kilo)); /* converting in Farad from here to the end */ + ftoa(r,buf,6,1); + + strcat(fbuf,out[4]); + strcat(fbuf,buf); + + do{ + puts("Capacity value (Def. 20) C [micoFarad] -> "); /* Capacity C */ + c=(double)atof(gets(buf)); + } while (c<=0); + + c=(double)(c*(micro)); /* converting in Farad from here to the end */ + ftoa(c,buf,6,1); /* new value of c in buf (only for show)*/ + + strcat(fbuf,out[5]); + strcat(fbuf,buf); + + puts("Initial charge condition (Def. 0) (@t=0s) vc(0) [Volt] -> "); /* Iniztial charge condition vc(0) */ + yinit=(double)atof(gets(buf)); + + strcat(fbuf,out[6]); + strcat(fbuf,buf); + + /* calc and set parameters */ + tau=(double)(r*c); /* Tau=R*C R [Ohm] C [Farad]*/ + /*cnt=(int)(time/h);*/ + + strcat(fbuf,out[7]); + ftoa((time/h),buf,0,1); /* 0 decimal like int */ + strncpy(conv,buf,4); /* save cnt to conv first 4 digit*/ + strcat(fbuf,buf); + + puts(fbuf); /* Input data Review */ + + puts("Do you want to review input data (Y/N)?"); + rev=getch(); +if (rev == 'Y' || rev == 'y') goto IN; + + /* reset buffers */ + fbuf[0]='\0'; + buf[0]='\0'; + + /* set screen */ + scr_clear(); + scr_curs(0,0); + + /* Simulation data review */ + puts("Simulation parameters set:"); + scr_curs(2,0); + puts("Number of input cycles:"); + scr_curs(2,31); + puts(conv); + puts("Input voltage E="); + scr_curs(3,31); + puts(ftoa(sur,buf,4,1)); /* 14 digits in double precision */ + scr_curs(3,50); + puts("V"); + puts("Init value vc(0)="); + scr_curs(4,31); + puts(ftoa(yinit,buf,4,1)); + scr_curs(4,50); + puts("V"); + puts("Circuit time constant Tau=R*C="); + scr_curs(5,31); + puts(ftoa(tau,buf,14,1)); + scr_curs(5,50); + puts("s"); + puts("Time step integration h="); + scr_curs(6,31); + puts(ftoa(h,buf,6,1)); + scr_curs(6,50); + puts("s"); + puts("Time simulation ts = "); + scr_curs(7,31); + puts(ftoa(time,buf,4,1)); + scr_curs(7,50); + puts("s"); + puts(""); + + puts("Do you want to plot exact solution too (Y/N)?"); + rev=getch(); + if (rev == 'Y' || rev == 'y') z=1; + + rev='1'; + puts("Select the method [1]= RK4 - [2]= RKF(4)5"); + rev=getch(); + /*puts("Press any key to start simulation..."); + getch();*/ + if (rev=='2') return 2; + else return 1; + + + return 0; +} + diff --git a/scr/OV2.C b/scr/OV2.C new file mode 100644 index 0000000..05b61e3 --- /dev/null +++ b/scr/OV2.C @@ -0,0 +1,207 @@ +/* Copyright (C) 2013 Riccardo Greco rigreco.grc@gmail.com. +* +* This project is based on 1999-2000 Thesis work of Greco Riccardo. +* It implement an Runge Kutta 4(5)^ order integration numerical method of differential equations set +* by use of double precision floating point operation in Aztec C65 language. +* It allow to simulate different mathematical models such as: +* Resistance Capacitor electrical circuit, Direct Current electric motor, +* Alternative Current three phase induction motor. +* +* Thanks to Bill Buckels for his invaluable support: +* Aztec C compilers http://www.aztecmuseum.ca/compilers.htm +*/ +/* PROCESS MODULE */ +#include +#include +#include +#include +#define chk 1 /* set chk to 1 charge */ +#define rk4r 5.0e-3 /* RK4 max resolution hrk4r); /* RK4 max resolution */ + + /* y3 plus weighted average of operators 4^ order */ + y3[0] = (double)(y+(r1+y3err*r2+y3err*r3+r4)/y3div); + +} + +ovmain() +{ +char buf[20],rev;/*conv[4]*/ +double atof(); /* DON'T FORGET THIS */ +double x,x2,nc,y3,y,errtx,cur,exa; +struct data rk; + + + /* inizialization */ + cnt=(int)0.0; /* Reset counter */ + y3 = (double)0.0; + x=(double)0.0; /* time simulation */ + x2=(double)0.0; /* time discharge */ + keep=(double)0.0; + + swi=(double)1.0; /* switch set to 1 = charge */ + y=yinit; /* set initial condition parameter vc(o) */ + + /* Start simulation */ + scr_clear(); + scr_curs(0,0); + puts("Pocessing..."); + + /* open and write header data to file */ + open(FILE_NAME,O_WRONLY|O_APPEND,0xC3); + write(fd,fbuf,80); + + buf[0]='\0'; /* buffers reset */ + fbuf[0]='\0'; + + /* RK main Cycle */ + while (x time2) + { + if (chk) + { + swi=(double)0.0; /* switch set to 0 = discharge */ + keep=(double)y3; /* keep the value of vc(td) in the istant of discharge */ + !chk; /* NOT chk */ + } + exa=(double)exact2(x2); + errtx=(double)fabs(y3-exa); /* exact solution in discharge */ + x2=x2+h; + } + + /* store output in buffer */ + ftoa(x,buf,6,2); + strcat(fbuf,outr[0]); + strcat(fbuf,buf); /* store time (x) */ + + ftoa(y3,buf,6,2); + strcat(fbuf,outr[1]); + strcat(fbuf,buf); /* store voltage vc(t) (y3) */ + + ftoa(errtx,buf,6,2); + strcat(fbuf,outr[2]); + strcat(fbuf,buf); /* store voltage error vcerr(t) (errtx) */ + + ftoa(cur,buf,6,2); + strcat(fbuf,outr[3]); + strcat(fbuf,buf); /* store current i(t) (cur) */ + + + /* converting using max floating resolution */ + ftoa(y3,rk.v,14,1); /* vc(t) */ + ftoa(cur,rk.i,14,1); /* i(t) */ + ftoa(exa,rk.ideal,14,1); /* vc(t) exact solution */ + + puts(fbuf); /* output to screen */ + + /* write data result to file */ + write(fd,rk.v,20); /* write vc(t) */ + write(fd,rk.i,20); /* write i(t) */ + write(fd,rk.ideal,20); /* write vc(t) exact solution */ + + fbuf[0]='\0'; /* reset buffer */ + y=y3; + x=x+h; + cnt++; /* renew counter */ + + } + close(fd); /* close the data file */ + + /*printf("Cycles number= %d",(cnt-1)); /* NOT YET itoa ? */ + + + puts("Press any key to start plotting..."); + getch(); + + return 0; +} + diff --git a/scr/OV2F.c b/scr/OV2F.c new file mode 100644 index 0000000..ceaaae3 --- /dev/null +++ b/scr/OV2F.c @@ -0,0 +1,243 @@ +/* Copyright (C) 2013 Riccardo Greco rigreco.grc@gmail.com. +* +* This project is based on 1999-2000 Thesis work of Greco Riccardo. +* It implement an Runge Kutta 4(5)^ order integration numerical method of differential equations set +* by use of double precision floating point operation in Aztec C65 language. +* It allow to simulate different mathematical models such as: +* Resistance Capacitor electrical circuit, Direct Current electric motor, +* Alternative Current three phase induction motor. +* +* Thanks to Bill Buckels for his invaluable support: +* Aztec C compilers http://www.aztecmuseum.ca/compilers.htm +*/ +/* PROCESS MODULE */ +#include +#include +#include +#include +#define chk 1 /* set chk to 1 charge */ +#define rkfr 1.0e-6 /* RKF max resolution h=4) h=4*h; + else h=sigma*h; + /* Alternative method + if (err>=emax) h=h/2; + if (err<=emin) h=h*2; + + if (h>hmax) h=hmax; */ + /* + } + while (err>rkfr); + */ + + /* y3 weighted average of operators 5^ order */ + y3[0]=(double)(y+(ips5[0]*r1+ips5[2]*r3+ips5[3]*r4+ips5[4]*r5)*h); +} + +ovmain() +{ +char buf[20],rev; +double atof(); /* DON'T FORGET THIS */ +double x,x2,nc,y3,y,errtx,cur,exa; +struct data rk; + + + /* inizialization */ + cnt=(int)0.0; /* Reset counter */ + y3 = (double)0.0; + x=(double)0.0; /* time in simulation */ + x2=(double)0.0; /* time in discharge */ + keep=(double)0.0; + + swi=(double)1.0; /* switch set to 1 = charge */ + y=yinit; /* set initial condition parameter vc(o) */ + /*h=hmax; /* need for adaptative step */ + + /* Start simulation */ + scr_clear(); + scr_curs(0,0); + puts("Pocessing..."); + + /* open and write header data to file */ + open(FILE_NAME,O_WRONLY|O_APPEND,0xC3); + write(fd,fbuf,80); + + buf[0]='\0'; /* buffers reset */ + fbuf[0]='\0'; + + /* RK main Cycle */ + while (x time2) + { + if (chk) + { + swi=(double)0.0; /* switch set to 0 = discharge */ + keep=(double)y3; /* keep the value of vc(td) in the istant of discharge */ + !chk; /* NOT chk */ + } + exa=(double)exact2(x2); + errtx=(double)fabs(y3-exa); /* exact solution in discharge */ + x2=x2+h; /* increment time in discharge */ + } + + + /* store output in buffer */ + ftoa(x,buf,6,2); + strcat(fbuf,outr[0]); + strcat(fbuf,buf); /* store time (x) */ + + ftoa(y3,buf,6,2); + strcat(fbuf,outr[1]); + strcat(fbuf,buf); /* store voltage vc(t) (y3) */ + + ftoa(errtx,buf,6,2); + strcat(fbuf,outr[2]); + strcat(fbuf,buf); /* store voltage error vcerr(t) (errtx) */ + + ftoa(cur,buf,6,2); + strcat(fbuf,outr[3]); + strcat(fbuf,buf); /* store current i(t) (cur) */ + + /* converting using max floating resolution */ + ftoa(y3,rk.v,14,1); /* vc(t) */ + ftoa(cur,rk.i,14,1); /* i(t) */ + ftoa(exa,rk.ideal,14,1); /* vc(t) exact solution */ + + puts(fbuf); /* output to screen */ + + /* write data result to file */ + write(fd,rk.v,20); /* write vc(t) */ + write(fd,rk.i,20); /* write i(t) */ + write(fd,rk.ideal,20); /* write vc(t) exact solution */ + + fbuf[0]='\0'; /* reset buffer */ + + y=y3; + x=x+h; /* increment time in simulation */ + cnt++; /* renew counter */ + + } + close(fd); /* close the data file */ + + /*printf("Cycles number= %d",(cnt-1)); /* NOT YET itoa ?*/ + + puts("Press any key to start plotting..."); + getch(); + + return 0; +} + diff --git a/scr/OV3.c b/scr/OV3.c new file mode 100644 index 0000000..934364c --- /dev/null +++ b/scr/OV3.c @@ -0,0 +1,123 @@ +/* Copyright (C) 2013 Riccardo Greco rigreco.grc@gmail.com. +* +* This project is based on 1999-2000 Thesis work of Greco Riccardo. +* It implement an Runge Kutta 4(5)^ order integration numerical method of differential equations set +* by use of double precision floating point operation in Aztec C65 language. +* It allow to simulate different mathematical models such as: +* Resistance Capacitor electrical circuit, Direct Current electric motor, +* Alternative Current three phase induction motor. +* +* Thanks to Bill Buckels for his invaluable support: +* Aztec C compilers http://www.aztecmuseum.ca/compilers.htm +*/ +#include +#include +#include +#include "d2monplt.h" + +/* GENERAL GLOBAL */ +extern double h,keep; +extern char fbuf[80]; +extern int cnt,fd,z; /* x FILE LOW lEVEL DON'T FORGET THIS */ +extern struct data { + char v[20]; + char i[20]; + char ideal[20]; + }; + +/* LOCAL GLOBAL */ +char *FILE_NAME="rcrk"; + +ovmain() +{ + +double nc,vr,ir,exa,xscale,iscale,vscale; +int plotx,ploty,plotey,ic,px,py; +struct data rk; +double atof(); /* DON'T FORGET THIS */ +char tx[4]; + /* inizialization */ + + px=(int)0.0; + py=(int)0.0; + ic=(int)0.0; + xscale=(double)100.0; /* set x scale plot */ + iscale=(double)2500.0; /* set y (i(t)) scale plot */ + vscale=(double)1.0; /* set y (vc(t)) scale plot */ + nc=(double)0.0; + + + /* GRAPHICS SECTION */ + + /* Axes */ + for (px=0,py=96;px<=560;++px) + { + d2monoplot(px,py,py,1); + /*d2monoplot(px,py-sur,py-sur,2); /* final voltage value E */ + } /*Axis X */ + + /* + for (px=0,py=0;py<=192;++py) + { + d2monoplot(px,py,py,1); + } /* Axis Y */ + + /* labels */ + monoplots("t=",505,36,1,'M'); + monoplots("v(t)=",25,0,1,'M'); + monoplots("i(t)=",25,10,1,'M'); + + /* read first recort (header) for increment file pointr */ + open(FILE_NAME,O_RDONLY,0xC3); + read(fd,fbuf,80); + + /* Main Plot */ + for (ic=0;ic +#include +#include +#include + +/* GENERAL GLOBAL */ + +extern int fd; /* x FILE LOW lEVEL DON'T FORGET THIS */ + +/* LOCAL GLOBAL */ + +char *FILE_NAME1="rcrk"; +char *FILE_NAME2="dcrk"; + +/* pointing to unused memory at 4192 for a buffer + if this gives problems change to something else */ +struct fileinfo *fi = (struct fileinfo *)4192; + +int p8create(name, maintype, subtype ) +char *name; +unsigned maintype,subtype; +{ + int fh; + + /* overwrite file if it already exists - set all access */ + if((fh=open(name, O_WRONLY|O_TRUNC|O_CREAT,0xc3)) == -1) return fh; + /* close it and get prodos to change the filetype for you */ + close(fh); + + /* get the fileinfo from ProDOS */ + if (getfinfo (name, fi) == -1) { + return -2; + } + + /* set the file info to whatever you wish - + you can set other info as well using this call sequence */ + fi->file_type = (unsigned char)maintype; + fi->aux_type = subtype; + setfinfo(name,fi); + + /* open the file again */ + fh=open(name, O_WRONLY,0xc3); + /* return the open handle */ + return fh; +} + +ovmain(filename) +unsigned filename; +{ + +switch(filename) + { + case 1: + /* create or or owerwrite output file BIN format */ + fd=p8create(FILE_NAME1,6,0); + break; + case 2: + /* create or or owerwrite output file BIN format */ + fd=p8create(FILE_NAME2,6,0); + } + + if (fd == -1) + { if (errno == EACCES) + { + puts("unable to access file"); + getch(); + /*_exit();*/ + } + else if (errno == ENOENT) + { + puts("unable to open file"); + getch(); + /*_exit();*/ + } + else + { + puts("open error number"); + puts(errno); + getch(); + /*_exit();*/ + } + } + else if (fd==-2) + { puts("do not get fileinfo"); + } + close(fd); + + /*getch(); */ + return 0; +} + diff --git a/scr/RCRK.C b/scr/RCRK.C new file mode 100644 index 0000000..740b82f --- /dev/null +++ b/scr/RCRK.C @@ -0,0 +1,92 @@ +/* Copyright (C) 2013 Riccardo Greco rigreco.grc@gmail.com. +* +* This project is based on 1999-2000 Thesis work of Greco Riccardo. +* It implement an Runge Kutta 4(5)^ order integration numerical method of differential equations set +* by use of double precision floating point operation in Aztec C65 language. +* It allow to simulate different mathematical models such as: +* Resistance Capacitor electrical circuit, Direct Current electric motor, +* Alternative Current three phase induction motor. +* +* Thanks to Bill Buckels for his invaluable support: +* Aztec C compilers http://www.aztecmuseum.ca/compilers.htm +*/ +#include + + +/* GENERAL GLOBAL */ + +double h,time,time2,sur,r,c,tau,yinit,keep; +char fbuf[80]; +int cnt,fd,fd2,z; +struct data { + char v[20]; + char i[20]; + char ideal[20]; + }; + +int clearhgr(i) +int i; +{ + +/* Funzioni globali devono essere in modulo principale per essere condivisi +tra sovrapposizioni */ +if (i!=911) + {return 0;} +maintoaux (0,0,0); +black(); +hgr(); + +} + +main() +{ +int a,b,c; + z=0; + b=0; + c=0; +clearhgr(0); +IN: + a=ovloader("mainm"); + switch (a){ + case 0: + _exit(); + break; + case 1: + b=ovloader("ov1"); /* input module */ + if (b==2) { + ovloader("p8file",1); /* create or owerwrite work file */ + ovloader("ov2f"); /* process module by RKF45*/ + } + else { + ovloader("p8file",1); /* create or owerwrite work file rcrk*/ + ovloader("ov2"); /* process module by RK4*/ + } + ovloader("ginit",1); /* open graph mode */ + ovloader("ov3"); /*output module */ + ovloader("ginit",2); /* close graph mode */ + break; + case 2: + ovloader("indc"); + ovloader("p8file",2); /* create or owerwrite work file dcrk*/ + ovloader("dcmotor"); + ovloader("ginit",1); /* open graph mode */ + ovloader("outdc"); /*output module */ + ovloader("ginit",2); /* close graph mode */ + c=1; + break; + case 5: + if(b==1 || b==2){ + ovloader("outf",1);} /* create output file from rcrk */ + else if(c==1){ + ovloader("outf",2);} /* create output file from dcrk */ + break; + case 6: + ovloader("saveg"); + break; + default: + break; + } +goto IN; + +} + diff --git a/scr/SAVEg.c b/scr/SAVEg.c new file mode 100644 index 0000000..8df211c --- /dev/null +++ b/scr/SAVEg.c @@ -0,0 +1,32 @@ +/* Copyright (C) 2013 Riccardo Greco rigreco.grc@gmail.com. +* +* This project is based on 1999-2000 Thesis work of Greco Riccardo. +* It implement an Runge Kutta 4(5)^ order integration numerical method of differential equations set +* by use of double precision floating point operation in Aztec C65 language. +* It allow to simulate different mathematical models such as: +* Resistance Capacitor electrical circuit, Direct Current electric motor, +* Alternative Current three phase induction motor. +* +* Thanks to Bill Buckels for his invaluable support: +* Aztec C compilers http://www.aztecmuseum.ca/compilers.htm +*/ +#include + +/* LOCAL GLOBAL */ +char *FILE_Graph="Graph"; + +ovmain() +{ + scr_clear(); + scr_curs(0,0); + + /* bsave HGR2 */ + bsave(FILE_Graph); + + puts("Graph has been saved!"); + scr_curs(5,0); + puts("Press any key ..."); + + getch(); +return 0; +} diff --git a/scr/outf.c b/scr/outf.c new file mode 100644 index 0000000..cf47ee9 --- /dev/null +++ b/scr/outf.c @@ -0,0 +1,166 @@ +/* Copyright (C) 2013 Riccardo Greco rigreco.grc@gmail.com. +* +* This project is based on 1999-2000 Thesis work of Greco Riccardo. +* It implement an Runge Kutta 4(5)^ order integration numerical method of differential equations set +* by use of double precision floating point operation in Aztec C65 language. +* It allow to simulate different mathematical models such as: +* Resistance Capacitor electrical circuit, Direct Current electric motor, +* Alternative Current three phase induction motor. +* +* Thanks to Bill Buckels for his invaluable support: +* Aztec C compilers http://www.aztecmuseum.ca/compilers.htm +*/ +#include +#include +#include +#include + +/* GENERAL GLOBAL */ +extern double h,time; +extern char fbuf[80]; +extern int cnt,fd,fd2; /* x FILE LOW lEVEL DON'T FORGET THIS */ +extern struct data { + char v[20]; + char i[20]; + char ideal[20]; + }; + +/* LOCAL GLOBAL */ +char *outr1[4]={" t="," vc(t)="," i(t)="," ve(t)="}; +char *outr2[3]={" t="," ia(t)="," w(t)="}; + +char *FILE_OUT="rkout"; +char *FILE_NAME1="rcrk"; +char *FILE_NAME2="dcrk"; + +char *null=" "; + +ovmain(outfile) +unsigned outfile; +{ +char buf[20],fbuf2[30]; +int ic; +double nc; +struct data rk; + + /* inizialization */ + ic=(int)0.0; + nc=(double)0.0; + fbuf[0]='\0'; + fbuf2[0]='\0'; + buf[0]='\0'; + + scr_clear(); + scr_curs(0,0); + + puts("Pocessing output file..."); + + /* open or overwrite output text file */ + fd2=open(FILE_OUT, O_WRONLY|O_TRUNC|O_CREAT,0xc3); + + switch(outfile) + { + case 1: /***** RC *****/ + /* open and read header from process file rcrk*/ + fd=open(FILE_NAME1,O_RDONLY,0xC3); + read(fd,fbuf,80); + break; + case 2: /***** DC *****/ + /* open and read header from process file dcrk*/ + fd=open(FILE_NAME2,O_RDONLY,0xC3); + read(fd,fbuf,80); + } + + /* open and write header to output file */ + open(FILE_OUT,O_WRONLY|O_APPEND,0xC3); + write(fd2,fbuf,80); + + /* reset buffer */ + fbuf[0]='\0'; + fbuf2[0]='\0'; + buf[0]='\0'; + + + + switch(outfile) + { + case 1: + for (ic=0;ic