ReadBinaryIntArray_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 /*READS MATLAB CELL-ARRAYS OF INTS AS CODED BY writeBinaryIntArray_mex.C ints
0002 are Matlabs int32*/ 
0003 
0004 #include <stdlib.h>
0005 #include <stdio.h>
0006 #include "Fokker_Planck_DKE_loop.h"
0007 
0008 void ReadBinaryIntArray_DKE(char* file,struct IntTensor **Array)
0009 {
0010 FILE* TENSOR;
0011 int i;
0012 int cookie;
0013 /*fprintf(stdout,"Opening\n");*/
0014 TENSOR=fopen(file,"r");
0015 if(!TENSOR){printf("couldn't open file\n");}
0016 /*fprintf(stdout,"Reading cookie\n");*/
0017 fread(&cookie,sizeof(int),1,TENSOR);
0018 /*fprintf(stdout,"TEST COOKIE\n");
0019 fprintf(stdout,"%i\n",cookie);*/
0020 if(cookie==0){
0021 int j,k;
0022 int mc,*nc;
0023 int pc=1,p=1;
0024 /*File is a CELL ARRAY*/
0025 /* fprintf(stdout,"CELL ARRAY\n");*/
0026 /* fprintf(stdout,"reading m\n");*/
0027 fread(&mc,sizeof(int),1,TENSOR);
0028 if(mc!=2){return;}
0029 nc=malloc(mc*sizeof(int));
0030 fread(nc,sizeof(int),mc,TENSOR);
0031 fread(&pc,sizeof(int),1,TENSOR);
0032 
0033 *Array=malloc(sizeof(**Array)*pc);
0034 
0035    for(i=0;ifor(j=0;jint),1,TENSOR);/* fprintf(stdout,"%i\n",(*Array)[i+nc[0]*j].ndims)*/;
0039       (*Array)[i+nc[0]*j].sizedim=malloc((*Array)[i+nc[0]*j].ndims*sizeof(int));
0040       fread((*Array)[i+nc[0]*j].sizedim,sizeof(int),(*Array)[i+nc[0]*j].ndims,TENSOR);
0041      
0042 fread(&((*Array)[i+nc[0]*j].size),sizeof(int),1,TENSOR);/* fprintf(stdout,"%i\n",(*Array)[i+nc[0]*j].size)*/;
0043       ((*Array)[i+nc[0]*j].vals)=malloc((*Array)[i+nc[0]*j].size*sizeof(INT));
0044       fread((*Array)[i+nc[0]*j].vals,sizeof(INT),(*Array)[i+nc[0]*j].size,TENSOR);
0045          for(k=0;k<(*Array)[i+nc[0]*j].size;k++){
0046          /*fprintf(stdout,"%i\n",(*Array)[i+nc[0]*j].vals[k]);*/
0047          }
0048       }
0049    }
0050 }
0051 
0052 else if(cookie==1){
0053 /*File is a numerical array*/
0054 *Array=malloc(sizeof(**Array)*1);
0055 /*fprintf(stdout,"reading Array ndims\n");*/
0056 fread(&((**Array).ndims),sizeof(int),1,TENSOR);
0057 
0058 (**Array).sizedim=malloc((**Array).ndims*sizeof(int));
0059 fread((**Array).sizedim,sizeof(int),(**Array).ndims,TENSOR);
0060 
0061 fread(&((**Array).size),sizeof(int),1,TENSOR);
0062 
0063 ((**Array).vals)=malloc((**Array).size*sizeof(int));
0064 fread((**Array).vals,sizeof(int),(**Array).size,TENSOR);
0065 }
0066 
0067 
0068 fclose(TENSOR);
0069 /*fprintf(stdout,"end read\n");*/
0070 }

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