NCEPLIBS-bacio  2.5.0
bacio.c File Reference

Fortran-callable routines to read and write characther data byte addressably. More...

#include <stdio.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>
#include "clib.h"

Go to the source code of this file.

Functions

int baciol (int mode, long int start, int size, long int no, long int *nactual, int *fdes, const char *fname, void *datary)
 Do a bacio operation. More...
 

Detailed Description

Fortran-callable routines to read and write characther data byte addressably.

v1.1:

  • Put diagnostic output under control of define VERBOSE or QUIET
  • Add option of non-seeking read/write
  • Return code for fewer data read/written than requested

    v1.2:

  • Add cray compatibility 20 April 1998 Robert Grumbine

    v1.3:

  • Add IBMSP compatibility (IBM4, IBM8)
  • Add modes BAOPEN_WONLY_TRUNC, BAOPEN_WONLY_APPEND
  • Use isgraph instead of isalnum + a short list of accepted characters for filename check 12 Dec 2000 Stephen Gilbert
  • negative return codes are wrapped to positive, revise return codes verify that banio and bacio have same contents, update comments 29 Oct 2008 Robert Grumbine

    v1.4:

  • 21 Nov 2008 Add baciol and baniol functions, versions to work with files over 2 Gb Robert Grumbine
  • Aug 2012 Jun Wang fix c filename length because the c string needs to end with "null" terminator , and free allocated cfile name realname to avoid memory leak.
  • Sep 2012 Jun Wang: remove execute permission on the data file generated by bacio.

v2.5: Oct. 2021 - Ed Hartnett - Extensive cleanup, testing, and refactor. Converted to use ISO C/Fortran compatibility.

Author
Robert Grumbine
Date
16 March 1998

Definition in file bacio.c.

Function Documentation

◆ baciol()

int baciol ( int  mode,
long int  start,
int  size,
long int  no,
long int *  nactual,
int *  fdes,
const char *  fname,
void *  datary 
)

Do a bacio operation.

Available operations include:

  • opening a file.
  • writing to an open file.
  • reading from an open file.
  • closing an open file.
Parameters
modeSpecifies operations to be performed. See the clib.inc file for the values. Mode is obtained by adding together the values corresponding to the operations The best method is to include the clib.inc file and refer to the names for the operations rather than rely on hard-coded values.
startByte number to start your operation from. 0 is the first byte in the file, not 1.
sizeThe size of the objects you are trying to read or write (i.e. the size of one element of the type - 4 for integers, for example.)
noThe number of elements to read or write (characters, integers, whatever).
nactualA pointer that gets the number of elements actually read or written. If the read/write operation succeeded, this will equal the value of parameter no.
fdesPointer that gets an integer file id. This is not a Fortran Unit Number You can use it, however, to refer to files you've previously opened.
fnameis the name of the file. This only needs to be defined when you are opening a file. It must be (on the Fortran side) declared as CHARACTER*N, where N is a length greater than or equal to the length of the file name.
dataryis the name of the entity (variable, vector, array) that you want to write data out from or read it in to. The fact that C is declaring it to be a char * does not affect your fortran.

This function is called from the Fortran code in baciof.f90.

Returns
BA_NOERROR No error.
BA_EROANDWO Tried to open read only and write only.
BA_ERANDW Tried to read and write in the same call.
BA_EINTNAME Internal failure in name processing.
BA_EFILEOPEN Failure in opening file.
BA_ERONWO Tried to read on a write-only file.
BA_ERNOSTART Failed in read to find the 'start' location.
BA_EWANDRO Tried to write to a read only file.
BA_EWNOSTART Failed in write to find the 'start' location.
BA_ECLOSE Error in close.
BA_EFEWDATA Read or wrote fewer data than requested.
BA_EDATANULL Data pointer is NULL.
Author
Robert Grumbine
Date
21 November 2008
Author
Ed Hartnett
Date
18 October, 2021

< Open file read only.

< Open or create file for Write only.

< Open or create a file for write only, truncating existing contents.

< Open or create a file for write only append.

< Tried to open read only and write only.

< Read from an open file.

< Write to an open file.

< Tried to read and write in the same call.

< Open file read only.

< Open or create file for Write only.

< Open or create a file for write only, truncating existing contents.

< Open or create a file for write only append.

< Open or create file for read/write.

< Failure in opening file.

< Read from an open file.

< Open or create file for Write only.

< Open or create a file for write only, truncating existing contents.

< Open or create a file for write only append.

< Tried to read on a write-only file.

< Read from an open file.

< No seek ignore start parameter and do not call lseek().

< Failed in read to find the 'start' location.

< Data pointer is NULL.

< Write to an open file.

< Open file read only.

< Tried to write to a read only file.

< Write to an open file.

< No seek ignore start parameter and do not call lseek().

< Failed in write to find the 'start' location.

< Data pointer is NULL.

< Close an open file.

< Error in close.

< Read from an open file.

< Write to an open file.

< Read or wrote fewer data than requested.

< No error.

Definition at line 101 of file bacio.c.

References BA_ECLOSE, BA_EDATANULL, BA_EFEWDATA, BA_EFILEOPEN, BA_ERANDW, BA_ERNOSTART, BA_EROANDWO, BA_ERONWO, BA_EWANDRO, BA_EWNOSTART, BA_NOERROR, BACLOSE, BAOPEN_RONLY, BAOPEN_RW, BAOPEN_WONLY, BAOPEN_WONLY_APPEND, BAOPEN_WONLY_TRUNC, BAREAD, BAWRITE, and NOSEEK.