Illegal use of floating point???

I have to code a program to calculate magnetization and strain. I have everything working except for the "INPUT LOAD"(bold lines). It returns as an illegal use of floating point. What is going on??? Any help will be appreciated. Thank you.

# include <stdio.h>
# include <stdlib.h>
# include <conio.h>
# include <math.h>
# include <string.h>

# define KTOL 500000
# define Num_pos 100

FILE *pout;

char text[Num_pos];
char in_file [Num_pos];
char out_file [Num_pos];

double t1_v[Num_pos],t2_v[Num_pos];
double def_v[Num_pos],H_v[Num_pos];

double sigma,defr_max,def_tr;
double S,mi_0,rho;
double Msat;
double Hs_12,Hf_12,Hs_21,Hf_21;
double DS;
double A,B1,B2,C,Y;

double def_0,H_0,xi_0;
double t0,tf,dt,tol,tol_2;

double xi,xi_ant,xi_ant_ant,xi_teste;
double xi_1,xi_1_teste;
double H,H_ant;
double def,def_ant;

double j,t,Pi;

double sigma_b;

int np_H,np_def;

/*********************** INPUT "NAME OF THE FILE.in" ***********************/
void leitura (void)
{
FILE *pin;

pin = fopen ("teste_kiefer.in","r");

/************************ INPUT MATERIAL PROPERITIES ************************/

fscanf (pin,"%s\n",&out_file);
fscanf (pin,"%lf %lf %lf\n",&sigma,&defr_max,&def_tr);
fscanf (pin,"%lf %lf\n",&mi_0,&rho);
fscanf (pin,"%lf\n",&Msat);
fscanf (pin,"%lf\n",&DS);
fscanf (pin,"%lf %lf %lf %lf\n",&Hs_12,&Hf_12,&Hs_21,&Hf_21);

/******************************** INPUT LOAD ********************************/

fscanf (pin,"%d\n",&np_def);

for (j=1;j<=np_def;j++)
{
fscanf (pin,"%lf %lf\n",&t1_v[j],&def_v[j]);
}


fscanf (pin,"%d\n",&np_H);

for (j=1;j<=np_H;j++)
{
fscanf (pin,"%lf %lf\n",&t2_v[j],&H_v[j]);
}

/**************************** INITIAL CONDITIONS ****************************/

/*********************** xi_1 - fase M-; xi - fase M; ***********************/


fscanf (pin,"%lf %lf %lf\n",&def_0,&H_0,&xi_0);

/**************************** CONTROL VARIABLES *****************************/

fscanf (pin,"%lf %lf %lf %lf %lf %lf\n",&t0,&tf,&dt,&tol,&tol_2,&Pi);
}
/***************************** LOAD FUNCTION ******************************/

double carga (double t,int np,double *tm,double *cm)
{
double c,a;
int j,m;

for (m=1;m<=np-1;m++)
{
if ((t>=tm[m]) && (t<=tm[m+1]))
{
j = m;
}
}

a = (cm[j+1]-cm[j])/(tm[j+1]-tm[j]);
c = (cm[j]-a*tm[j])+a*t;

return c;
}

/************************** TO DEFINE PARAMETERS ***************************/
void proj (double H)
{

double db,xi_teste;

do
{

// Definition of the material constants and model parameters.

A = (((mi_0*Msat)/Pi)*(Hs_12-Hf_12));
B1 = (0.5*mi_0*Msat*(Hs_12+Hf_21)+sigma*defr_max);
C = (((mi_0*Msat)/Pi)*(Hf_21-Hs_21));
B2 = ((Pi/4)*(A-C));
Y = ((0.5*mi_0*Msat)*(Hs_12-Hf_21)- B2);

// Definition of the reorientation driving force.

if(t<=50.0)
{
xi_teste = xi_ant + ((0.5*cos(-(1/A)*(-sigma*defr_max - 0.5*DS*(pow(sigma,2)) - mi_0*Msat*H + B1 + B2 + Y)+ Pi) + 0.5)*dt);
}

else if ((t>50.0)&&(t<=100.0))
{
xi_teste = xi_ant + ((0.5*cos(-(1/C)*(-sigma*defr_max - 0.5*DS*(pow(sigma,2)) - mi_0*Msat*H + B1 - B2 - Y)+ Pi) + 0.5)*dt);
}

// Definiton of the reorientation constrains.

xi = xi_teste;
xi_1_teste = 1 - xi;

do
{
if ((xi - 1) > tol)
{
db = (1-xi);
xi = xi + db;
}

if (xi < tol)
xi = 0;

if (fabs(xi-1) < tol)
xi = 1;

}
while ((xi<0)||((xi - 1) >tol));

// Definition of the subloops constrains.

if ((H > H_ant) && (fabs(def) > fabs(def_ant)))
{
if (xi > xi_ant)
xi = xi_ant;
}

if ((H < H_ant) && (fabs(def) < fabs(def_ant)))
{
if (xi < xi_ant)
xi = xi_ant;
}

xi_1 = 1-xi;

}
while (((xi-xi_teste)>tol) && ((xi_1-xi_1_teste)>tol));
}

/************************** TO PRINT .dat FILES ***************************/
void imprime(void)
{

fprintf(pout,"%g %g %g %g\n",H,def,xi,xi_1,t);

}

/**************************** TO SOLVE STRAIN *****************************/
void solucao (void)

{

strcpy (text,out_file);
strcat (text,".dat");
pout = fopen(text,"w");


if (t==t0)
{
xi_ant = xi = xi_0;
xi_1 = 1-xi;

H_ant = H_0;
def_ant = def_0;

}

fprintf(pout,"Magnetic_Field Strain xi Time\n");

while (t<=tf)
{

def = S*sigma + defr_max*xi + def_tr;

imprime();
t = t + dt;

H_ant = H;
def_ant = def;

xi_ant_ant = xi_ant;

xi_ant = xi;

}
fclose(pout);
}

/****************************** MAIN ROUTINE ******************************/
void main (void)
{
clrscr ();
printf ("MAGNETIC SHAPE MEMORY MODELLING IN GIBBS\n");
leitura ();
printf ("\nSTART OF EXECUTION ...\n");
solucao();
printf ("\n ... END OF EXECUTION !!!\n");
}



Last edited on
1
2
double v[] = {0,1,2,3,4,5};
v[3.141592] //¿what is this supposed to return? 
use integer for the index

Also, limit the scope of your variables.
Topic archived. No new replies allowed.