NCEPLIBS-bacio  2.6.0
bacio.c File Reference

Fortran-callable C functions that read and write characther data. 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 C functions that read and write characther data.

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.

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

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.
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 71 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.