ReadBinaryArray_DKE

PURPOSE ^

C/C++ source

SYNOPSIS ^

C/C++ source

DESCRIPTION ^

C/C++ source

CROSS-REFERENCE INFORMATION ^

This function calls: This function is called by:

SOURCE CODE ^

0001 #include <stdlib.h>
0002 #include <stdio.h>
0003 #include "Fokker_Planck_DKE_loop.h"
0004 
0005 void ReadBinaryArray_DKE(char* file,struct Tensor **Array)
0006 {
0007 FILE* TENSOR;
0008 int i;
0009 int cookie;
0010 /*fprintf(stdout,"Opening\n");*/
0011 TENSOR=fopen(file,"r");
0012 
0013 /*fprintf(stdout,"Reading cookie\n");*/
0014 fread(&cookie,sizeof(int),1,TENSOR);
0015 /*fprintf(stdout,"TEST COOKIE\n");
0016 fprintf(stdout,"%i\n",cookie);*/
0017 if(cookie==0){
0018 int j,k;
0019 int mc,*nc;
0020 int pc=1,p=1;
0021 /*File is a CELL ARRAY*/
0022 /*fprintf(stdout,"CELL ARRAY\n");
0023 fprintf(stdout,"reading m\n");*/
0024 fread(&mc,sizeof(int),1,TENSOR);
0025 if(mc!=2){return;}
0026 nc=malloc(mc*sizeof(int));
0027 fread(nc,sizeof(int),mc,TENSOR);
0028 fread(&pc,sizeof(int),1,TENSOR);
0029 
0030 *Array=malloc(sizeof(**Array)*pc);
0031 
0032    for(i=0;ifor(j=0;jint),1,TENSOR);/* fprintf(stdout,"%i\n",(*Array)[i+nc[0]*j].ndims)*/;
0036       (*Array)[i+nc[0]*j].sizedim=malloc((*Array)[i+nc[0]*j].ndims*sizeof(int));
0037       fread((*Array)[i+nc[0]*j].sizedim,sizeof(int),(*Array)[i+nc[0]*j].ndims,TENSOR);
0038      
0039 fread(&((*Array)[i+nc[0]*j].size),sizeof(int),1,TENSOR);/* fprintf(stdout,"%i\n",(*Array)[i+nc[0]*j].size)*/;
0040       ((*Array)[i+nc[0]*j].vals)=malloc((*Array)[i+nc[0]*j].size*sizeof(DOUBLE));
0041       fread((*Array)[i+nc[0]*j].vals,sizeof(DOUBLE),(*Array)[i+nc[0]*j].size,TENSOR);
0042          for(k=0;k<(*Array)[i+nc[0]*j].size;k++){
0043     /* fprintf(stdout,"%g\n",(*Array)[i+nc[0]*j].vals[k]);*/
0044          }
0045       }
0046    }
0047 }
0048 
0049 else if(cookie==1){/*File is a numerical array*/
0050 /*fprintf(stdout,"reading Array ndims\n");*/
0051 fread(&((**Array).ndims),sizeof(int),1,TENSOR);
0052 
0053 (**Array).sizedim=malloc((**Array).ndims*sizeof(int));
0054 fread((**Array).sizedim,sizeof(int),(**Array).ndims,TENSOR);
0055 
0056 fread(&((**Array).size),sizeof(int),1,TENSOR);
0057 
0058 ((**Array).vals)=malloc((**Array).size*sizeof(DOUBLE));
0059 fread((**Array).vals,sizeof(DOUBLE),(**Array).size,TENSOR);
0060 }
0061 
0062 /*else if(cookie==1211216){/*File is a sparse matrix*/
0063 /*
0064 }*/
0065 
0066 fclose(TENSOR);
0067 /*fprintf(stdout,"end read\n");*/
0068 }

Community support and wiki are available on Redmine. Last update: 18-Apr-2019.