Skip to content

Commit

Permalink
added read_write fns
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@697 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
henjo committed Jan 28, 2002
1 parent 98985f9 commit 1b30074
Show file tree
Hide file tree
Showing 3 changed files with 63 additions and 1 deletion.
6 changes: 5 additions & 1 deletion c_runtime/Makefile
Expand Up @@ -4,11 +4,15 @@ CFLAGS = -Wall -ansi -pedantic



OBJS = boolean_array.o index_spec.o integer_array.o memory_pool.o real_array.o string_array.o
OBJS = boolean_array.o index_spec.o integer_array.o memory_pool.o \
real_array.o string_array.o read_write.o

all : libc_runtime.a


libc_runtime.a : $(OBJS)
$(AR) $@ $(OBJS)

clean :
rm -f libc_runtime.a
rm -f $(OBJS)
38 changes: 38 additions & 0 deletions c_runtime/read_write.c
@@ -0,0 +1,38 @@

#include "read_write.h"

void read_modelica_real(FILE* file, modelica_real* data)
{
float f;
fscanf(file,"%e",&f);
*data = f;
}

void read_real_array(FILE* file, real_array_t* arr)
{
int nr_elements;
int i;
float f;
nr_elements = real_array_nr_of_elements(arr);
for (i = 0; i < nr_elements; ++i)
{
fscanf(file,"%e",&f);
arr->data[i] = f;
}
}

void write_modelica_real(FILE* file, modelica_real* data)
{
fprintf(file,"%e\n",*data);
}

void write_real_array(FILE* file, real_array_t* arr)
{
int nr_elements;
int i;
nr_elements = real_array_nr_of_elements(arr);
for (i = 0; i < nr_elements; ++i)
{
fprintf(file,"%e",arr->data[i]);
}
}
20 changes: 20 additions & 0 deletions c_runtime/read_write.h
@@ -0,0 +1,20 @@
#ifndef READ_WRITE_H_
#define READ_WIRTE_H_

#include <stdio.h>
#include "modelica.h"

#define PRE_VARIABLES FILE *in_file,*out_file;int close_file;
#define PRE_OPEN_FILE(fv,fn,m,df) if(strcmp("-",fn)==0){fv=df;close_file=0;}else{fv=fopen(fn,m);close_file=1;if(!fv){return errno;}}

#define PRE_OPEN_INFILE PRE_OPEN_FILE(in_file,in_filename,"r",stdin)
#define PRE_OPEN_OUTFILE PRE_OPEN_FILE(out_file,out_filename,"w",stdout)
#define PRE_READ_DONE if (close_file) fclose(in_file);
#define PRE_WRITE_DONE if (close_file) fclose(out_file);

void read_modelica_real(FILE*,modelica_real*);
void read_real_array(FILE*,real_array_t*);
void write_modelica_real(FILE*,modelica_real*);
void write_real_array(FILE*,real_array_t*);

#endif

0 comments on commit 1b30074

Please sign in to comment.