Rleg  2
 All Data Structures Files Functions Variables Typedefs Macros Groups Pages
Data Structures | Typedefs | Functions
gmatlabdatafile.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "gmatlabdatafile.h"
Include dependency graph for gmatlabdatafile.c:

Go to the source code of this file.

Data Structures

struct  MATLAB_DATAHEAD
 

Typedefs

typedef struct MATLAB_DATAHEADPMATLAB_DATAHEAD
 

Functions

int gMATLABDataFile_OpenWrite (PGMATLABDATAFILECONFIG pGMatlabDataFileConfig, char *filename, char *dirname)
 
int gMATLABDataFile_OpenRead (PGMATLABDATAFILECONFIG pGMatlabDataFileConfig, char *filename, char *dirname)
 
void gMATLABDataFile_Close (PGMATLABDATAFILECONFIG pGMatlabDataFileConfig)
 
int gMATLABDataFile_SaveVector (PGMATLABDATAFILECONFIG pGMatlabDataFileConfig, const char *varname, double *v, long nlin)
 
int gMATLABDataFile_SaveMatrix (PGMATLABDATAFILECONFIG pGMatlabDataFileConfig, const char *varname, double **m, long nlin, long ncol)
 

Typedef Documentation

Function Documentation

void gMATLABDataFile_Close ( PGMATLABDATAFILECONFIG  pGMatlabDataFileConfig)

Definition at line 58 of file gmatlabdatafile.c.

References GMATLABDATAFILECONFIG::fp.

Referenced by gDataLogger_Close().

59 {
60  fclose(pGMatlabDataFileConfig->fp);
61 
62 }

Here is the caller graph for this function:

int gMATLABDataFile_OpenRead ( PGMATLABDATAFILECONFIG  pGMatlabDataFileConfig,
char *  filename,
char *  dirname 
)

Definition at line 40 of file gmatlabdatafile.c.

References FALSE, GMATLABDATAFILECONFIG::FileName, GMATLABDATAFILECONFIG::FlagStillNotSaved, GMATLABDATAFILECONFIG::fp, and TRUE.

41 {
42  pGMatlabDataFileConfig->FileName[0] = '\0';
43  if(dirname!=NULL)
44  sprintf(pGMatlabDataFileConfig->FileName,"%s",dirname);
45  strcat(pGMatlabDataFileConfig->FileName,filename);
46  pGMatlabDataFileConfig->FlagStillNotSaved = TRUE;
47 
48  pGMatlabDataFileConfig->fp = fopen(pGMatlabDataFileConfig->FileName, "r");
49  if(pGMatlabDataFileConfig->fp==NULL){
50  return FALSE;
51  }
52  rewind(pGMatlabDataFileConfig->fp);
53 
54  return TRUE;
55 
56 }
#define FALSE
#define TRUE
int gMATLABDataFile_OpenWrite ( PGMATLABDATAFILECONFIG  pGMatlabDataFileConfig,
char *  filename,
char *  dirname 
)

Definition at line 21 of file gmatlabdatafile.c.

References FALSE, GMATLABDATAFILECONFIG::FileName, GMATLABDATAFILECONFIG::FlagStillNotSaved, GMATLABDATAFILECONFIG::fp, and TRUE.

Referenced by gDataLogger_Init().

22 {
23  pGMatlabDataFileConfig->FileName[0] = '\0';
24  if(dirname!=NULL)
25  sprintf(pGMatlabDataFileConfig->FileName,"%s",dirname);
26  strcat(pGMatlabDataFileConfig->FileName,filename);
27  pGMatlabDataFileConfig->FlagStillNotSaved = TRUE;
28 
29  pGMatlabDataFileConfig->fp = fopen(pGMatlabDataFileConfig->FileName, "w");
30  if(pGMatlabDataFileConfig->fp==NULL){
31  printf("\n pGMatlabDataFileConfig->fp==NULL: %s",pGMatlabDataFileConfig->FileName);
32  return FALSE;
33  }
34  rewind(pGMatlabDataFileConfig->fp);
35 
36  return TRUE;
37 
38 }
#define FALSE
#define TRUE

Here is the caller graph for this function:

int gMATLABDataFile_SaveMatrix ( PGMATLABDATAFILECONFIG  pGMatlabDataFileConfig,
const char *  varname,
double **  m,
long  nlin,
long  ncol 
)

Definition at line 92 of file gmatlabdatafile.c.

References FALSE, GMATLABDATAFILECONFIG::FlagStillNotSaved, GMATLABDATAFILECONFIG::fp, MATLAB_DATAHEAD::imagf, MATLAB_DATAHEAD::mrows, MATLAB_DATAHEAD::namlen, MATLAB_DATAHEAD::ncols, TRUE, and MATLAB_DATAHEAD::type.

93 {
94  MATLAB_DATAHEAD DataHead;
95  int nl,nc;
96  double *vcol;
97 
98  DataHead.type = (long)(0);
99  DataHead.mrows = (long)(nlin);
100  DataHead.ncols = (long)(ncol);
101  DataHead.imagf = (long)(0);
102  DataHead.namlen = (long)(strlen(varname)+1);
103 
104  if(! fwrite(&DataHead, sizeof(MATLAB_DATAHEAD), 1, pGMatlabDataFileConfig->fp) ){
105  return FALSE;
106  }
107 
108  if(! fwrite(varname, sizeof(char), (strlen(varname)+1), pGMatlabDataFileConfig->fp)){
109  return FALSE;
110  }
111 
112  vcol = (double*)malloc(nlin*sizeof(double));
113 
114  for(nc=0;nc<ncol;++nc){
115  for(nl=0;nl<nlin;++nl){
116  vcol[nl] = m[nl][nc];
117  }
118  if(! fwrite(vcol, sizeof(double), nlin, pGMatlabDataFileConfig->fp)){
119  free(vcol);
120  return FALSE;
121  }
122  }
123  free(vcol);
124 
125  pGMatlabDataFileConfig->FlagStillNotSaved = FALSE;
126 
127  return(TRUE);
128 
129 }
#define FALSE
#define TRUE
int gMATLABDataFile_SaveVector ( PGMATLABDATAFILECONFIG  pGMatlabDataFileConfig,
const char *  varname,
double *  v,
long  nlin 
)

Definition at line 64 of file gmatlabdatafile.c.

References FALSE, GMATLABDATAFILECONFIG::FlagStillNotSaved, GMATLABDATAFILECONFIG::fp, MATLAB_DATAHEAD::imagf, MATLAB_DATAHEAD::mrows, MATLAB_DATAHEAD::namlen, MATLAB_DATAHEAD::ncols, TRUE, and MATLAB_DATAHEAD::type.

Referenced by gDataLogger_Close(), and gDataLogger_MatfileUpdate().

65 {
66  MATLAB_DATAHEAD DataHead;
67 
68  DataHead.type = (long)(0);
69  DataHead.mrows = (long)(nlin);
70  DataHead.ncols = (long)(1);
71  DataHead.imagf = (long)(0);
72  DataHead.namlen = (long)(strlen(varname)+1);
73 
74  if(! fwrite(&DataHead, sizeof(MATLAB_DATAHEAD), 1, pGMatlabDataFileConfig->fp) ){
75  return FALSE;
76  }
77 
78  if(! fwrite(varname, sizeof(char), (strlen(varname)+1), pGMatlabDataFileConfig->fp)){
79  return FALSE;
80  }
81 
82  if(! fwrite(v, sizeof(double), nlin, pGMatlabDataFileConfig->fp)){
83  return FALSE;
84  }
85 
86  pGMatlabDataFileConfig->FlagStillNotSaved = FALSE;
87 
88  return(TRUE);
89 
90 }
#define FALSE
#define TRUE

Here is the caller graph for this function: