nco/nco_bnr.h File Reference

#include <stdio.h>
#include <netcdf.h>
#include "nco_netcdf.h"
#include "nco.h"
#include "nco_ctl.h"

Include dependency graph for nco_bnr.h:

This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

FILE * nco_bnr_open (const char *const fl_bnr)
int nco_bnr_close (FILE *fp_bnr, const char *const fl_bnr)
size_t nco_bnr_wrt (FILE *const fp_bnr, const char *const var_nm, const long var_sz, const nc_type var_typ, const void *const void_ptr)


Function Documentation

int nco_bnr_close FILE *  fp_bnr,
const char *const   fl_bnr
 

Definition at line 29 of file nco_bnr.c.

References dbg_lvl_get(), EXIT_FAILURE, nco_exit(), and prg_nm_get().

Referenced by main().

00031 {
00032   /* Purpose: Close unformatted binary data file for writing */
00033   int rcd; /* [rcd] Return code */
00034   /* Close output file */
00035   rcd=fclose(fp_bnr);
00036   if(rcd != 0){
00037     (void)fprintf(stderr,"%s: ERROR unable to close binary output file %s\n",prg_nm_get(),fl_bnr);
00038     nco_exit(EXIT_FAILURE);
00039   } /* end if */
00040   if(dbg_lvl_get() > 2) (void)fprintf(stdout,"\n");
00041   if(dbg_lvl_get() > 1) (void)fprintf(stdout,"%s: Closed binary file %s\n",prg_nm_get(),fl_bnr);
00042   return rcd; /* O [rcd] Return code */
00043 } /* end nco_bnr_close() */

FILE* nco_bnr_open const char *const   fl_bnr  ) 
 

Definition at line 13 of file nco_bnr.c.

References dbg_lvl_get(), EXIT_FAILURE, FILE, nco_exit(), and prg_nm_get().

Referenced by main().

00014 {
00015   /* Purpose: Open unformatted binary data file for writing */
00016   FILE *fp_bnr; /* [fl] Unformatted binary output file handle */
00017   /* Open output file */
00018   if((fp_bnr=fopen(fl_bnr,"w")) == NULL){
00019     (void)fprintf(stderr,"%s: ERROR unable to open binary output file %s\n",prg_nm_get(),fl_bnr);
00020     nco_exit(EXIT_FAILURE);
00021   } /* end if */
00022   if(dbg_lvl_get() > 1) (void)fprintf(stdout,"%s: Opened binary file %s\n",prg_nm_get(),fl_bnr);
00023   if(dbg_lvl_get() > 2) (void)fprintf(stdout,"Variable(s): Name (native type, # elements x bytes per element):\n");
00024   return fp_bnr; /* O [fl] Unformatted binary output file handle */
00025 } /* end nco_bnr_open() */

size_t nco_bnr_wrt FILE *const   fp_bnr,
const char *const   var_nm,
const long  var_sz,
const nc_type  var_typ,
const void *const   void_ptr
 

Definition at line 47 of file nco_bnr.c.

References c_typ_nm(), dbg_lvl_get(), EXIT_FAILURE, nco_exit(), nco_typ_lng(), and prg_nm_get().

Referenced by nco_cpy_var_val(), nco_cpy_var_val_lmt(), and nco_cpy_var_val_mlt_lmt().

00052 {
00053   /* Purpose: Write unformatted binary data */
00054   /* Testing:
00055      ncks -O -D 3 -B -b foo.bnr ~/nco/data/in.nc ~/nco/data/foo.nc */
00056 
00057   long wrt_nbr; /* [nbr] Number of elements successfully written */
00058   /* Write unformatted data to binary output file */
00059   wrt_nbr=fwrite(void_ptr,(size_t)nco_typ_lng(var_typ),(size_t)var_sz,fp_bnr);
00060   if(wrt_nbr != var_sz){
00061     (void)fprintf(stderr,"%s: ERROR only succeeded in writing %ld of %ld elements of variable %s\n",prg_nm_get(),wrt_nbr,var_sz,var_nm);
00062     nco_exit(EXIT_FAILURE);
00063   } /* end if */
00064   if(dbg_lvl_get() > 2) (void)fprintf(stdout,"%s (%s, %ld x %lu b), ",var_nm,c_typ_nm(var_typ),var_sz,(unsigned long)nco_typ_lng(var_typ));
00065   if(dbg_lvl_get() > 0) (void)fflush(stderr);
00066   return wrt_nbr; /* O [nbr] Number of elements successfully written */
00067 } /* end nco_bnr_wrt() */


Generated on Thu Mar 16 18:15:13 2006 for nco by  doxygen 1.4.4