cross platform i/o problem [message #5861] |
Fri, 01 March 1996 00:00 |
mbastian
Messages: 3 Registered: March 1994
|
Junior Member |
|
|
Hi Peter
I transfer binary back and forth between vax's and unicies all the time.
It is not clear to me if you are using formated or unformated reads/writes.
For binary files the vax fortran i/o places a two byte record delimeter at
the start of each record (0x3). Prepend these two each unformated write and
your problems should go away.
I have a few C #define to do all this for me when I want to produce unformated
fortran binary files in c.
the following is not particularly pretty but hey this is VMS after all !!!
#if defined (unix)
#define BINARY_EXTENSIONS
#define FREAD(a,b,c,d) fread (a,b,c,d)
#define FWRITE(a,b,c,d) fwrite (a,b,c,d)
#else
#include <stdlib.h>
#define BINARY_EXTENSIONS ,"rfm=var"
#define FREAD(a,b,c,d) { \
int z; \
char * ptr_1 , * ptr_2; \
ptr_1 = malloc ( b + 2 ); \
ptr_2 = ( char * ) a; \
for ( z = 0 ; z < c ; z ++ ) { \
fread ( ptr_1 , b + 2 , 1 , d ); \
memmove ( ptr_2 , ptr_1 + 2 , b ); \
ptr_2 += b; \
} \
free ( ptr_1 ); \
}
#define FWRITE(a,b,c,d) { \
int z; \
char * ptr_1 , * ptr_2; \
ptr_1 = malloc ( b + 2 ); \
* ( short * ) ptr_1 = 0x3; \
ptr_2 = ( char * ) a; \
for ( z = 0 ; z < c ; z ++ ) { \
memmove ( ptr_1 + 2 , ptr_2 , b ); \
fwrite ( ptr_1 , b + 2 , 1 , d ); \
ptr_2 += b; \
} \
free ( ptr_1 ); \
}
#endif
/* open data file */
if (( fd = fopen ( file , "rb" BINARY_EXTENSIONS)) == NULL ) {
fprintf ( stderr , "Could not open in file %s\n" , file );
exit ( -1 );
}
Hope this helps ...
--
Matthew Bastian
Institute for Aerospace Research
National Research Council of Canada
613-998-3337
Matthew.Bastian@nrc.ca
|
|
|