You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
simulacion-permeabilidad/fftma_module/gen/LIB_IO/readdata3.c

207 lines
5.7 KiB
C

#include <stdio.h>
#include <stddef.h>
#include <string.h>
#include <stdarg.h>
#include <stdlib.h>
#include "genlib.h"
#include "simpio.h"
#include "geostat.h"
#include "pressure.h"
#include "toolsIO.h"
void readdata3(long *seed,struct grid_mod *grid,string filename[8],struct vario_mod *variogram,struct statistic_mod *stat,struct pressure_mod *pression,int *Ksolver,int *genere, int *gwnwrite, int *format_file,int *Psolver, struct realization_mod *Kfield,struct realization_mod *gwnoise, char *argv[])
{
FILE *fp;
int i,j,n;
char *file1,*file2,*file3,*file4,*file5;
char *prog=argv[0];
double tmp;
file1=argv[1];
file2=argv[2];
/* Ouverture du fichier de données principal */
if ((fp=fopen(file1,"r")) == NULL)
{
fprintf(stderr,"%s :impossible d'ouvrir %s\n",prog, file1);
exit(1);
}
else
{
*Ksolver = atoi(ReadLine(fp));
*genere = atoi(ReadLine(fp));
*gwnwrite = atoi(ReadLine(fp));
if (*gwnwrite==0)
{
filename[0] = ReadLine(fp);
}
*format_file=atoi(ReadLine(fp));
*Psolver=atoi(ReadLine(fp));
(*grid).NX = atoi(ReadLine(fp));
(*grid).NY = atoi(ReadLine(fp));
(*grid).NZ = atoi(ReadLine(fp));
(*grid).DX = atof(ReadLine(fp));
(*grid).DY = atof(ReadLine(fp));
(*grid).DZ = atof(ReadLine(fp));
fclose(fp);
}
n=(*grid).NX*(*grid).NY*(*grid).NZ;
/* Ouverture du fichier de données sur le champ de perméabilité */
if ((fp=fopen(file2,"r")) == NULL)
{
fprintf(stderr,"%s :impossible d'ouvrir %s\n",prog, file2);
exit(1);
}
else
{
*seed=atoi(ReadLine(fp));
(*variogram).Nvario = atoi(ReadLine(fp));
(*variogram).vario = (int *) malloc((*variogram).Nvario * sizeof(int));
(*variogram).alpha = (double *) malloc((*variogram).Nvario * sizeof(double));
(*variogram).ap = (double *) malloc(9*(*variogram).Nvario * sizeof(double));
(*variogram).scf = (double *) malloc(3*(*variogram).Nvario * sizeof(double));
(*variogram).var = (double *) malloc((*variogram).Nvario * sizeof(double));
for (i= 0; i < (*variogram).Nvario; i++) {
(*variogram).var[i] = atof(ReadLine(fp));
(*variogram).vario[i] = atoi(ReadLine(fp));
(*variogram).alpha[i] = atof(ReadLine(fp));
for (j = 0; j < 3; j++)
(*variogram).scf[i*3+j]= atof(ReadLine(fp));
for (j = 0; j < 6; j++)
(*variogram).ap[i*9+j] = atof(ReadLine(fp));
}
/*statistical data*/
(*stat).nblock_mean = 1;
(*stat).nblock_var = 1;
(*stat).mean = (double *)malloc((*stat).nblock_mean * sizeof(double));
if ((*stat).mean == NULL)
Error("No memory available");
(*stat).variance = (double *)malloc((*stat).nblock_var * sizeof(double));
if ((*stat).variance == NULL)
Error("No memory available");
(*stat).mean[0] = atof(ReadLine(fp));
(*stat).variance[0] = atof(ReadLine(fp));
(*stat).type = atoi(ReadLine(fp));
filename[1] = ReadLine(fp);
fclose(fp);
}
switch (*Ksolver)
{
case 0:
/* Ouverture du fichier contenant le gaussian white noise */
if (*genere == 1)
{
file3=argv[3];
if ((fp=fopen(file3,"r")) == NULL)
{
fprintf(stderr,"%s :impossible d'ouvrir %s\n",prog, file3);
exit(1);
}
else
{
/* Ouverture du champ de permeabilite K */
(*gwnoise).vector = (double *) malloc(n * sizeof(double));
for (i=0;i<n;i++)
{
/* (*gwnoise).vector[i]=atof(ReadLine(fp)); */
/* sscanf(ReadLine(fp)," %Lf %c",gwnoise.vector[i],&merde); */
fscanf(fp,"%lf",&tmp);
(*gwnoise).vector[i]= tmp;
}
fclose(fp);
}
}
break;
case 1:
file3=argv[3];
/* Ouverture du fichier de données de pression*/
if ((fp=fopen(file3,"r")) == NULL)
{
fprintf(stderr,"%s :impossible d'ouvrir %s\n",prog, file3);
exit(1);
}
else
{
/* testopenfile(fp); */
filename[2] = ReadLine(fp);
filename[3] = ReadLine(fp);
(*pression).x = atof(ReadLine(fp));
(*pression).y = atof(ReadLine(fp));
(*pression).z = atof(ReadLine(fp));
filename[4] = ReadLine(fp);
filename[5] = ReadLine(fp);
filename[6] = ReadLine(fp);
filename[7] = ReadLine(fp);
fclose(fp);
}
/* Ouverture du champ de permeabilite K */
(*Kfield).vector = (double *) malloc(n * sizeof(double));
file4=argv[4];
if ((fp=fopen(file4,"r")) == NULL)
{
fprintf(stderr,"%s :impossible d'ouvrir %s\n",prog, file4);
exit(1);
}
else
{
for (i=0;i<n;i++)
(*Kfield).vector[i]=atof(ReadLine(fp));
fclose(fp);
}
break;
case 2:
/* Ouverture du fichier de données de pression */
file3=argv[3];
if ((fp=fopen(file3,"r")) == NULL)
{
fprintf(stderr,"%s :impossible d'ouvrir %s\n",prog, file3);
exit(1);
}
else
{
/* testopenfile(fp); */
filename[2] = ReadLine(fp);
filename[3] = ReadLine(fp);
(*pression).x = atof(ReadLine(fp));
(*pression).y = atof(ReadLine(fp));
(*pression).z = atof(ReadLine(fp));
filename[4] = ReadLine(fp);
filename[5] = ReadLine(fp);
filename[6] = ReadLine(fp);
filename[7] = ReadLine(fp);
fclose(fp);
}
/* Ouverture du fichier contenant le gaussian white noise */
if (*genere == 1)
{
file4=argv[4];
if ((fp=fopen(file4,"r")) == NULL)
{
fprintf(stderr,"%s :impossible d'ouvrir %s\n",prog, file3);
exit(1);
}
else
{
/* Ouverture du champ de permeabilite K */
(*gwnoise).vector = (double *) malloc(n * sizeof(double));
for (i=0;i<n;i++)
(*gwnoise).vector[i]=atof(ReadLine(fp));
fclose(fp);
}
}
break;
}
return;
}