File Exchange

image thumbnail

Read VAXD and VAXG files in R2008b and later

version 1.7.0.1 (20.3 KB) by Michael Agostini
These functions allow the user to read VAXD and VAXG files in MATLAB R2008b and later.

1 Download

Updated 01 Sep 2016

View License

In R2008b, fopen no longer supports vaxd and vaxg file formats. This tool lets your use the ieee-le file format to read these files in R2008b and later. These tools are not for writing vaxd or vaxg files. Though you could write VAXF_to_uint32le.m, VAXD_to_uint64le.m, and VAXG_to_uint64le.m functions as well as fwriteVAXD.m and fwriteVAXG.m files if you wanted to enerate new files in VAXD or VAXG formats.
VAXD and VAXG are two methods VAX uses for representing floating point double precision numbers. VAX has a single method for representing single precision floating point numbers, VAXF. A VAXD encoded file uses VAXD standard for double precision and VAXF for single precision. A VAXG encoded file uses VAXG for double precision and VAXF for single precision. Information for how numbers are encoded can be found here: http://www.opengroup.org/onlinepubs/9629399/chap14.htm#tagfcjh_20

To patch your code:
1) Open your file with the 'ieee-le' format instead of 'vaxd' or 'vaxg'.
2) Replace fread commands with freadVAXD and freadVAXG functions.

Notes:
1) freadVAXD and freadVAXG assume three input arguments whereas the fread in MATLAB can take a number of different input arguments.
2) All code is written in MATLAB. Speed might be improved by writing C-MEX functions.

Example:

If your code originally looked like this:

fid = fopen('myfile', 'r', 'vaxd');
A = fread(fid, 2, 'double');
A = fread(fid, 3, 'uint32');
fclose(fid);

You would change your code to look like this:

fid = fopen('myfile', 'r', 'ieee-le');
A = freadVAXD(fid, 2, 'double');
A = freadVAXD(fid, 3, 'uint32');
fclose(fid);

Contains:

anExampleVADG.m - code to test the accuracy (and generate data file on R2008a or earlier)
freadVAXD.m - reads files assuming vaxd 64bit double precision floating point numbers and vaxf single precision floating point numbers
freadVAXG.m - reads files assuming vaxg 64bit double precision floating point numbers and vaxf single precision floating point numbers
uint32le_to_VAXF.m - converts 1 uint32 bit number into a floating point number (assuming vaxf encoding)
uint64le_to_VAXD.m - converts 2 uint32 bit numbers into a floating point number (assuming vaxd encoding)
uint64le_to_VAXG.m - converts 2 uint32 bit numbers into a floating point number (assuming vaxg encoding)
readme.txt - this file
testData.mat - sample data
test_vaxd - the sample data encoded in vaxd and vaxf double/single floating point numbers
test_vaxg - the sample data encoded in vaxg and vaxf double/single floating point numbers

Cite As

Michael Agostini (2020). Read VAXD and VAXG files in R2008b and later (https://www.mathworks.com/matlabcentral/fileexchange/22675-read-vaxd-and-vaxg-files-in-r2008b-and-later), MATLAB Central File Exchange. Retrieved .

Comments and Ratings (6)

David Francis

James Tursa

@Stephanie: Try posting a question on the Newsgroup or Answers forums. I am familiar with this conversion process and may be able to help you.

Stephanie

I have converted my reading program to use this function and checking to make sure the data is still read in the same and I am seeing problems. It is not reading in many of the numbers correctly. Where do I go for help? Steph

Michael Agostini

James, I've read your comments here and under Seth's post. I'll make the corrections and get them up. Thanks for your help.

James Tursa

This submission has a serious bug, it does not convert 0 properly. To fix this problem, add the following lines at the very end of these files:

uint32le_to_VAXF.m
floatVAXF(uint32le==0) = 0;

uint64le_to_VAXD.m
doubleVAXD(sum(uint32le,2)==0) = 0;

uint64le_to_VAXG.m
doubleVAXG(sum(uint32le,2)==0) = 0;

Aditya

Please see the following submission for writing data in VAX file format using MATLAB 7.7 (R2008b) and later releases:

http://www.mathworks.com/matlabcentral/fileexchange/24793

Updates

1.7.0.1

Updated license

1.7.0.0

Improved zero checking algorithm to include numbers with zero sign and exponent bits but non-zero mantisa bits.

Expanded test suite to include 0, inf, NaN, realmax, etc. Note VAX doesn't define/store some of these(inf, NaN, etc.)

1.6.0.0

Fixed a bug. Zeros now read in as zeros rather than very small (<1E-38) numbers.

1.5.0.0

Fixed a bug. Zeros now read in as zeros rather than very small (<1E-38) numbers.

1.4.0.0

Updated copyright notice

1.3.0.0

Cleaned up some typos

1.1.0.0

Cleaned up formating in the description section.

MATLAB Release Compatibility
Created with R2008b
Compatible with any release
Platform Compatibility
Windows macOS Linux