/******************************************************************************
* Copyright 1996-2014 United States Government as represented by the
* Administrator of the National Aeronautics and Space Administration.
* All Rights Reserved.
******************************************************************************/
/******************************************************************************
*
*  NSSDC/CDF                            CDF Standard Interface (III) /FORTRAN.
*
*  Version 3.1, 26-May-05, Raytheon ITSS.
*
*  Modification history:
*
*   V1.0  26-May-05, M Liu      Original version (for CDF V3.1).
*   V1.1  26-Jue-09, M Liu      Added CDF_select_cdf function.
*
******************************************************************************/

/******************************************************************************
*    This is the third part of the extended FORTRAN interfaces.
******************************************************************************/

#include "cdflib.h"

/******************************************************************************
*  CDF_confirm_attr_existence.
******************************************************************************/

VISIBLE_PREFIX
Fif_PREFIXa
Int32
Fif_PREFIXb
Fif_ENTRYPOINT(cdf_confirm_attr_existence__,
               cdf_confirm_attr_existence_,
               cdf_confirm_attr_existence,
               CDF_CONFIRM_ATTR_EXISTENCE)
(id, attr_name Fif_GHOSTARG(len))
Int32     *id;                  /* In: CDF identifier. */
void      *attr_name;           /* In: Attribute name. */
Fif_GHOSTDEF(len)               /* Invisible length of "attr_name"
                                   (generated by FORTRAN compiler). */
{
  struct STRINGstruct *ssh = NULL;      /* Head of STRINGstruct linked list. */
  Int32 status;

  status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id),
                           CONFIRM_, ATTR_EXISTENCE_,
#if defined(Fif_DESCR)
                                      DESCRtoREFnul(attr_name,
                                                    CDF_ATTR_NAME_LEN256,
                                                    &ssh),
#endif
#if defined(Fif_GHOSTLEN)
                                      NULterminate(attr_name,Fif_GHOSTUSE(len),
                                                   &ssh),
#endif
#if defined(Fif_NOLEN)
                                      FindEndNUL(attr_name,
                                                 CDF_ATTR_NAME_LEN256,
                                                 &ssh),
#endif
                           NULL_);

  return status;
}

/******************************************************************************
*  CDF_confirm_zvar_existence.
******************************************************************************/

VISIBLE_PREFIX
Fif_PREFIXa
Int32
Fif_PREFIXb
Fif_ENTRYPOINT(cdf_confirm_zvar_existence__,
               cdf_confirm_zvar_existence_,
               cdf_confirm_zvar_existence,
               CDF_CONFIRM_ZVAR_EXISTENCE)
(id, var_name Fif_GHOSTARG(len))
Int32     *id;                  /* In: CDF identifier. */
void      *var_name;            /* In: zVariable name. */
Fif_GHOSTDEF(len)               /* Invisible length of "var_name"
                                   (generated by FORTRAN compiler). */
{
  struct STRINGstruct *ssh = NULL;      /* Head of STRINGstruct linked list. */
  Int32 status;

  status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id),
                           CONFIRM_, zVAR_EXISTENCE_,
#if defined(Fif_DESCR)
                                      DESCRtoREFnul(var_name,
                                                    CDF_VAR_NAME_LEN256,
                                                    &ssh),
#endif
#if defined(Fif_GHOSTLEN)
                                      NULterminate(var_name,Fif_GHOSTUSE(len),
                                                   &ssh),
#endif
#if defined(Fif_NOLEN)
                                      FindEndNUL(var_name,
                                                 CDF_VAR_NAME_LEN256,
                                                 &ssh),
#endif
                           NULL_);

  return status;
}

/******************************************************************************
*  CDF_confirm_gentry_existence.
******************************************************************************/

VISIBLE_PREFIX
Fif_PREFIXa
Int32
Fif_PREFIXb
Fif_ENTRYPOINT(cdf_confirm_gentry_existence__,
               cdf_confirm_gentry_existence_,
               cdf_confirm_gentry_existence,
               CDF_CONFIRM_GENTRY_EXISTENCE)
(id, attr_num, entry_num)
Int32     *id;                  /* In: CDF identifier. */
Int32     *attr_num;            /* In: Attribute number. */
Int32     *entry_num;           /* In: gEntry number. */
{
  Int32 status;

  status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id),
                                    ATTR_, (long) (*attr_num - 1),
                           CONFIRM_, gENTRY_EXISTENCE_,
                                                     (long) (*entry_num - 1),
                           NULL_);

  return status;
}

/******************************************************************************
*  CDF_confirm_rentry_existence.
******************************************************************************/

VISIBLE_PREFIX
Fif_PREFIXa
Int32
Fif_PREFIXb
Fif_ENTRYPOINT(cdf_confirm_rentry_existence__,
               cdf_confirm_rentry_existence_,
               cdf_confirm_rentry_existence,
               CDF_CONFIRM_RENTRY_EXISTENCE)
(id, attr_num, entry_num)
Int32     *id;                  /* In: CDF identifier. */
Int32     *attr_num;            /* In: Attribute number. */
Int32     *entry_num;           /* In: rEntry number. */
{
  Int32 status;

  status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id),
                                    ATTR_, (long) (*attr_num - 1),
                           CONFIRM_, rENTRY_EXISTENCE_,
                                                     (long) (*entry_num - 1),
                           NULL_);

  return status;
}

/******************************************************************************
*  CDF_confirm_zentry_existence.
******************************************************************************/

VISIBLE_PREFIX
Fif_PREFIXa
Int32
Fif_PREFIXb
Fif_ENTRYPOINT(cdf_confirm_zentry_existence__,
               cdf_confirm_zentry_existence_,
               cdf_confirm_zentry_existence,
               CDF_CONFIRM_ZENTRY_EXISTENCE)
(id, attr_num, entry_num)
Int32     *id;                  /* In: CDF identifier. */
Int32     *attr_num;            /* In: Attribute number. */
Int32     *entry_num;           /* In: zEntry number. */
{
  Int32 status;

  status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id),
                                    ATTR_, (long) (*attr_num - 1),
                           CONFIRM_, zENTRY_EXISTENCE_,
                                                     (long) (*entry_num - 1),
                           NULL_);

  return status;
}

/******************************************************************************
*  CDF_confirm_zvar_padvalue_exist.
******************************************************************************/

VISIBLE_PREFIX
Fif_PREFIXa
Int32
Fif_PREFIXb
Fif_ENTRYPOINT(cdf_confirm_zvar_padvalue_exist__,
               cdf_confirm_zvar_padvalue_exist_,
               cdf_confirm_zvar_padvalue_exist,
               CDF_CONFIRM_ZVAR_PADVALUE_EXIST)
(id, var_num)
Int32     *id;                  /* In: CDF identifier. */
Int32     *var_num;             /* In: zVariable number. */
{
  Int32 status;

  status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id),
                                    zVAR_, (long) (*var_num - 1),
                           CONFIRM_, zVAR_PADVALUE_,
                           NULL_);

  return status;
}

/******************************************************************************
*  CDF_set_decoding.
******************************************************************************/

VISIBLE_PREFIX
Fif_PREFIXa
void
Fif_PREFIXb
Fif_ENTRYPOINT(cdf_set_decoding__,
               cdf_set_decoding_,
               cdf_set_decoding,
               CDF_SET_DECODING)
(id, decoding, status)
Int32     *id;                  /* In: CDF identifier. */
Int32     *decoding;            /* In: CDF decoding. */
Int32     *status;              /* Out: CDF status code. */
{

  *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id),
                                     CDF_DECODING_, (long) *decoding,
                            NULL_);

  return;
}

/******************************************************************************
*  CDF_set_readonly_mode.
******************************************************************************/

VISIBLE_PREFIX
Fif_PREFIXa
void
Fif_PREFIXb
Fif_ENTRYPOINT(cdf_set_readonly_mode__,
               cdf_set_readonly_mode_,
               cdf_set_readonly_mode,
               CDF_SET_READONLY_MODE)
(id, mode, status)
Int32     *id;                  /* in: cdf identifier. */
Int32     *mode;                /* in: cdf readonly mode. */
Int32     *status;              /* out: cdf status code. */
{
  *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id),
                                     CDF_READONLY_MODE_, (long) *mode,
                            NULL_);

  return;
}

/******************************************************************************
*  CDF_set_negtoposfp0_mode.
******************************************************************************/

VISIBLE_PREFIX
Fif_PREFIXa
void
Fif_PREFIXb
Fif_ENTRYPOINT(cdf_set_negtoposfp0_mode__,
               cdf_set_negtoposfp0_mode_,
               cdf_set_negtoposfp0_mode,
               CDF_SET_NEGTOPOSFP0_MODE)
(id, mode, status)
Int32     *id;                  /* In: CDF identifier. */
Int32     *mode;                /* In: CDF negtoposfp0 mode. */
Int32     *status;              /* Out: CDF status code. */
{
  *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id),
                                     CDF_NEGtoPOSfp0_MODE_, (long) *mode,
                            NULL_);
  return;
}

/******************************************************************************
*  CDF_set_compress_cachesize.
******************************************************************************/

VISIBLE_PREFIX
Fif_PREFIXa
void
Fif_PREFIXb
Fif_ENTRYPOINT(cdf_set_compress_cachesize__,
               cdf_set_compress_cachesize_,
               cdf_set_compress_cachesize,
               CDF_SET_COMPRESS_CACHESIZE)
(id, cache_size, status)
Int32     *id;                  /* In: CDF identifier. */
Int32     *cache_size;          /* In: CDF compress cache size. */
Int32     *status;              /* Out: CDF status code. */
{
  *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id),
                                     COMPRESS_CACHESIZE_, (long) *cache_size,
                            NULL_);

  return;
}

/******************************************************************************
*  CDF_set_stage_cachesize.
******************************************************************************/

VISIBLE_PREFIX
Fif_PREFIXa
void
Fif_PREFIXb
Fif_ENTRYPOINT(cdf_set_stage_cachesize__,
               cdf_set_stage_cachesize_,
               cdf_set_stage_cachesize,
               CDF_SET_STAGE_CACHESIZE)
(id, cache_size, status)
Int32     *id;                  /* In: CDF identifier. */
Int32     *cache_size;          /* In: CDF stage cache size. */
Int32     *status;              /* Out: CDF status code. */
{
  *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id),
                                     STAGE_CACHESIZE_, (long) *cache_size,
                            NULL_);

  return;
}

/******************************************************************************
*  CDF_set_zvar_cachesize.
******************************************************************************/

VISIBLE_PREFIX
Fif_PREFIXa
void
Fif_PREFIXb
Fif_ENTRYPOINT(cdf_set_zvar_cachesize__,
               cdf_set_zvar_cachesize_,
               cdf_set_zvar_cachesize,
               CDF_SET_ZVAR_CACHESIZE)
(id, cache_size, status)
Int32     *id;                  /* In: CDF identifier. */
Int32     *cache_size;          /* In: CDF zVariable cache size. */
Int32     *status;              /* Out: CDF status code. */
{
  *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id),
                                     zVAR_CACHESIZE_, (long) *cache_size,
                            NULL_);

  return;
}

/******************************************************************************
*  CDF_set_zvars_cachesize.
******************************************************************************/

VISIBLE_PREFIX
Fif_PREFIXa
void
Fif_PREFIXb
Fif_ENTRYPOINT(cdf_set_zvars_cachesize__,
               cdf_set_zvars_cachesize_,
               cdf_set_zvars_cachesize,
               CDF_SET_ZVARS_CACHESIZE)
(id, cache_size, status)
Int32     *id;                  /* In: CDF identifier. */
Int32     *cache_size;          /* In: CDF zVariables's cache size. */
Int32     *status;              /* Out: CDF status code. */
{
  *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id),
                                     zVARs_CACHESIZE_, (long) *cache_size,
                            NULL_);

  return;
}

/******************************************************************************
*  CDF_set_zvar_seqpos.
******************************************************************************/

VISIBLE_PREFIX
Fif_PREFIXa
void
Fif_PREFIXb
Fif_ENTRYPOINT(cdf_set_zvar_seqpos__,
               cdf_set_zvar_seqpos_,
               cdf_set_zvar_seqpos,
               CDF_SET_ZVAR_SEQPOS)
(id, var_num, rec_num, indices, status)
Int32     *id;                  /* In: CDF identifier. */
Int32     *var_num;             /* In: CDF zVariable number. */
Int32     *rec_num;             /* In: CDF zVariable record number. */
Int32     indices[];            /* In: CDF zVariable indices. */
Int32     *status;              /* Out: CDF status code. */
{
  long numDims, indicesT[CDF_MAX_DIMS];
  int ix;

  *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id),
                                     zVAR_, (long) (*var_num - 1),
                            GET_, zVAR_NUMDIMS_, &numDims,
                            NULL_);

  if (StatusBAD(*status)) return;

  if (numDims > 0) {
    for (ix = 0; ix < (int) numDims; ix++)
      indicesT[ix] = (long) (indices[ix] - 1);
  } else 
    indicesT[0] = 0;

  *status = (Int32) CDFlib (SELECT_, zVAR_SEQPOS_, (long) (*rec_num -1),
                                                   indicesT,
                            NULL_);

  return;
}

/******************************************************************************
*  CDF_set_zvar_reservepercent.
******************************************************************************/

VISIBLE_PREFIX
Fif_PREFIXa
void
Fif_PREFIXb
Fif_ENTRYPOINT(cdf_set_zvar_reservepercent__,
               cdf_set_zvar_reservepercent_,
               cdf_set_zvar_reservepercent,
               CDF_SET_ZVAR_RESERVEPERCENT)
(id, var_num, percent, status)
Int32     *id;                  /* In: CDF identifier. */
Int32     *var_num;             /* In: CDF zVariable number. */
Int32     *percent;             /* In: CDF zVariable reserve percentage. */
Int32     *status;              /* Out: CDF status code. */
{

  *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id),
                                     zVAR_, (long) (*var_num - 1),
                                     zVAR_RESERVEPERCENT_, (long) *percent,
                            NULL_);

  return;
}

/******************************************************************************
*  CDF_set_zmode.
******************************************************************************/

VISIBLE_PREFIX
Fif_PREFIXa
void
Fif_PREFIXb
Fif_ENTRYPOINT(cdf_set_zmode__,
               cdf_set_zmode_,
               cdf_set_zmode,
               CDF_SET_ZMODE)
(id, mode, status)
Int32     *id;                  /* In: CDF identifier. */
Int32     *mode;                /* In: CDF zMode. */
Int32     *status;              /* Out: CDF status code. */
{

  *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id),
                                     CDF_zMODE_, (long) *mode,
                            NULL_);

  return;
}

/******************************************************************************
*  CDF_set_attr_scope.
******************************************************************************/

VISIBLE_PREFIX
Fif_PREFIXa
void
Fif_PREFIXb
Fif_ENTRYPOINT(cdf_set_attr_scope__,
               cdf_set_attr_scope_,
               cdf_set_attr_scope,
               CDF_SET_ATTR_SCOPE)
(id, attr_num, attr_scope, status)
Int32     *id;                  /* In: CDF identifier. */
Int32     *attr_num;            /* In: Attribute number. */
Int32     *attr_scope;          /* In: Attribute scope. */
Int32     *status;              /* Out: CDF status code. */
{

  *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id),
                                     ATTR_, (long) (*attr_num - 1),
                            PUT_, ATTR_SCOPE_, (long) *attr_scope,
                            NULL_);

  return;
}

/******************************************************************************
*  CDF_set_attr_gentry_dataspec.
******************************************************************************/

VISIBLE_PREFIX
Fif_PREFIXa
void
Fif_PREFIXb
Fif_ENTRYPOINT(cdf_set_attr_gentry_dataspec__,
	       cdf_set_attr_gentry_dataspec_,
	       cdf_set_attr_gentry_dataspec,
	       CDF_SET_ATTR_GENTRY_DATASPEC)
(id, attr_num, entry_num, data_type, status)
Int32	  *id;		   	/* In: CDF identifier. */
Int32	  *attr_num;	   	/* In: Attribute number. */
Int32     *entry_num;           /* In: gEntry number. */
Int32     *data_type;           /* In: Data Type. */
Int32	  *status;		/* Out: CDF status code. */
{

  long scope;

  *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id),
                                     ATTR_, (long) (*attr_num - 1),
                            GET_, ATTR_SCOPE_, &scope,
                            NULL_);

  if (!StatusOK(*status)) return;

  if (GLOBALscope(scope)) {
    *status = (Int32) CDFlib (SELECT_, gENTRY_, (long) (*entry_num - 1),
                              PUT_,    gENTRY_DATASPEC_, (long) *data_type,
                                                         (long) -99,
			      NULL_);
  } else {
    *status = ILLEGAL_FOR_SCOPE;
  }

  return;
}

/******************************************************************************
*  CDF_set_attr_rentry_dataspec.
******************************************************************************/

VISIBLE_PREFIX
Fif_PREFIXa
void
Fif_PREFIXb
Fif_ENTRYPOINT(cdf_set_attr_rentry_dataspec__,
	       cdf_set_attr_rentry_dataspec_,
	       cdf_set_attr_rentry_dataspec,
	       CDF_SET_ATTR_RENTRY_DATASPEC)
(id, attr_num, entry_num, data_type, status)
Int32	  *id;		   	/* In: CDF identifier. */
Int32	  *attr_num;	   	/* In: Attribute number. */
Int32     *entry_num;           /* In: rEntry number. */
Int32     *data_type;           /* In: Data Type. */
Int32	  *status;		/* Out: CDF status code. */
{

  long scope;

  *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id),
                                     ATTR_, (long) (*attr_num - 1),
                            GET_, ATTR_SCOPE_, &scope,
                            NULL_);  

  if (!StatusOK(*status)) return;

  if (!GLOBALscope(scope)) {          
    *status = (Int32) CDFlib (SELECT_, rENTRY_, (long) (*entry_num - 1),
                              PUT_,    rENTRY_DATASPEC_, (long) *data_type,
                                                         (long) -99,
                              NULL_);
  } else {
    *status = ILLEGAL_FOR_SCOPE;
  }

  return;
}

/******************************************************************************
*  CDF_set_attr_zentry_dataspec.
******************************************************************************/

VISIBLE_PREFIX
Fif_PREFIXa
void
Fif_PREFIXb
Fif_ENTRYPOINT(cdf_set_attr_zentry_dataspec__,
	       cdf_set_attr_zentry_dataspec_,
	       cdf_set_attr_zentry_dataspec,
	       CDF_SET_ATTR_ZENTRY_DATASPEC)
(id, attr_num, entry_num, data_type, status)
Int32	  *id;		   	/* In: CDF identifier. */
Int32	  *attr_num;	   	/* In: Attribute number. */
Int32     *entry_num;           /* In: zEntry number. */
Int32     *data_type;           /* In: Data Type. */
Int32	  *status;		/* Out: CDF status code. */
{

  long scope;

  *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id),
                                     ATTR_, (long) (*attr_num - 1),
                            GET_, ATTR_SCOPE_, &scope,
                            NULL_);

  if (!StatusOK(*status)) return;

  if (!GLOBALscope(scope)) {
    *status = (Int32) CDFlib (SELECT_, zENTRY_, (long) (*entry_num - 1),
                              PUT_,    zENTRY_DATASPEC_, (long) *data_type,
                                                         (long) -99,
                              NULL_);
  } else {
    *status = ILLEGAL_FOR_SCOPE;
  }

  return;
}

/******************************************************************************
*  CDF_set_compression.
******************************************************************************/

VISIBLE_PREFIX
Fif_PREFIXa
void
Fif_PREFIXb
Fif_ENTRYPOINT(cdf_set_compression__,
               cdf_set_compression_,
               cdf_set_compression,
               CDF_SET_COMPRESSION)
(id, compress_type, compress_parms, status)
Int32	  *id;		   	/* In: CDF identifier. */
Int32     *compress_type;	/* In: CDF Compression type. */
Int32     compress_parms[];  	/* In: CDF Compression parameters. */
Int32     *status;              /* Out: CDF status code. */
{
  long cType, cParms[CDF_MAX_PARMS];
  int ix;

  cType = (long) *compress_type;
  for (ix = 0; ix < CDF_MAX_PARMS; ix++)
     cParms[ix] = (long) compress_parms[ix];

  *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id),
		            PUT_, CDF_COMPRESSION_, cType, cParms,
		            NULL_);
  return;
}

/******************************************************************************
*  CDF_set_encoding.
******************************************************************************/

VISIBLE_PREFIX
Fif_PREFIXa
void
Fif_PREFIXb
Fif_ENTRYPOINT(cdf_set_encoding__,
               cdf_set_encoding_,
               cdf_set_encoding,
               CDF_SET_ENCODING)
(id, encoding, status)
Int32	  *id;		   	/* In: CDF identifier. */
Int32     *encoding;		/* In: CDF encoding. */
Int32     *status;              /* Out: CDF status code. */
{

  *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id),
		            PUT_, CDF_ENCODING_, (long) *encoding,
		            NULL_);
  return;
}

/******************************************************************************
*  CDF_set_format.
******************************************************************************/

VISIBLE_PREFIX
Fif_PREFIXa
void
Fif_PREFIXb
Fif_ENTRYPOINT(cdf_set_format__,
               cdf_set_format_,
               cdf_set_format,
               CDF_SET_FORMAT)
(id, format, status)
Int32	  *id;		   	/* In: CDF identifier. */
Int32     *format;		/* In: CDF format. */
Int32     *status;              /* Out: CDF status code. */
{

  *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id),
		            PUT_, CDF_FORMAT_, (long) *format,
		            NULL_);
  return;
}

/******************************************************************************
*  CDF_set_majority.
******************************************************************************/

VISIBLE_PREFIX
Fif_PREFIXa
void
Fif_PREFIXb
Fif_ENTRYPOINT(cdf_set_majority__,
               cdf_set_majority_,
               cdf_set_majority,
               CDF_SET_MAJORITY)
(id, majority, status)
Int32	  *id;		   	/* In: CDF identifier. */
Int32     *majority;		/* In: CDF majority. */
Int32     *status;              /* Out: CDF status code. */
{

  *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id),
		            PUT_, CDF_MAJORITY_, (long) *majority,
		            NULL_);
  return;
}

/******************************************************************************
*  CDF_set_cachesize.
******************************************************************************/

VISIBLE_PREFIX
Fif_PREFIXa
void
Fif_PREFIXb
Fif_ENTRYPOINT(cdf_set_cachesize__,
               cdf_set_cachesize_,
               cdf_set_cachesize,
               CDF_SET_CACHESIZE)
(id, cache_size, status)
Int32     *id;                  /* In: CDF identifier. */
Int32     *cache_size;          /* In: CDF cache size. */
Int32     *status;              /* Out: CDF status code. */
{

  *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id),
                                     CDF_CACHESIZE_, (long) *cache_size,
                            NULL_);
  return;
}

/******************************************************************************
*  CDF_set_zvar_dataspec.
******************************************************************************/

VISIBLE_PREFIX
Fif_PREFIXa
void
Fif_PREFIXb
Fif_ENTRYPOINT(cdf_set_zvar_dataspec__,
               cdf_set_zvar_dataspec_,
               cdf_set_zvar_dataspec,
               CDF_SET_ZVAR_DATASPEC)
(id, var_num, data_type, status)
Int32     *id;          /* In: CDF identifier. */
Int32     *var_num;     /* In: CDF zVariable number. */
Int32     *data_type;   /* In: zVariable's data type. */
Int32     *status;      /* Out: CDF status code. */
{

  *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id),
                                     zVAR_, (long) (*var_num - 1),
                            PUT_, zVAR_DATASPEC_, (long) *data_type,
                                                  (long) -99,
                            NULL_);
  return;
}

/******************************************************************************
*  CDF_set_zvar_recvariance.
******************************************************************************/

VISIBLE_PREFIX
Fif_PREFIXa
void
Fif_PREFIXb
Fif_ENTRYPOINT(cdf_set_zvar_recvariance__,
               cdf_set_zvar_recvariance_,
               cdf_set_zvar_recvariance,
               CDF_SET_ZVAR_RECVARIANCE)
(id, var_num, rec_vary, status)
Int32     *id;          /* In: CDF identifier. */
Int32     *var_num;     /* In: CDF zVariable number. */
Int32     *rec_vary;    /* In: zVariable's record variance. */
Int32     *status;      /* Out: CDF status code. */
{

  *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id),
                                     zVAR_, (long) (*var_num - 1),
                            PUT_, zVAR_RECVARY_, (long) *rec_vary,
                            NULL_);
  return;
}

/******************************************************************************
*  CDF_set_zvar_dimvariances.
******************************************************************************/

VISIBLE_PREFIX
Fif_PREFIXa
void
Fif_PREFIXb
Fif_ENTRYPOINT(cdf_set_zvar_dimvariances__,
               cdf_set_zvar_dimvariances_,
               cdf_set_zvar_dimvariances,
               CDF_SET_ZVAR_DIMVARIANCES)
(id, var_num, dim_varys, status)
Int32     *id;          /* In: CDF identifier. */
Int32     *var_num;     /* In: CDF rVariable number. */
Int32     dim_varys[];  /* In: zVariable's dimensional variances. */
Int32     *status;      /* Out: CDF status code. */
{
  long numDims, dimVarys[CDF_MAX_DIMS];
  int ix;

  *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id),
                                     zVAR_, (long) (*var_num - 1),
                            GET_, zVAR_NUMDIMS_, &numDims,
                            NULL_);
  if (StatusBAD(*status)) return;

  if (numDims > 0) {
    for (ix = 0; ix < (int) numDims; ix++) 
      dimVarys[ix] = (long) dim_varys[ix];
  } else 
    dimVarys[0] = 0;

  *status = (Int32) CDFlib (PUT_, zVAR_DIMVARYS_, dimVarys,
                            NULL_);
  return;
}

/******************************************************************************
*  CDF_set_zvar_blockingfactor.
******************************************************************************/

VISIBLE_PREFIX
Fif_PREFIXa
void
Fif_PREFIXb
Fif_ENTRYPOINT(cdf_set_zvar_blockingfactor__,
               cdf_set_zvar_blockingfactor_,
               cdf_set_zvar_blockingfactor,
               CDF_SET_ZVAR_BLOCKINGFACTOR)
(id, var_num, blocking_factor, status)
Int32     *id;          /* In: CDF identifier. */
Int32     *var_num;     /* In: CDF zVariable number. */
Int32     *blocking_factor; /* Out: zVariable's blocking factor. */
Int32     *status;      /* Out: CDF status code. */
{

  *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id),
                                     zVAR_, (long) (*var_num - 1),
                            PUT_, zVAR_BLOCKINGFACTOR_,
                                                      (long) *blocking_factor,
                            NULL_);
  return;
}

/******************************************************************************
*  CDF_set_zvar_compression.
******************************************************************************/

VISIBLE_PREFIX
Fif_PREFIXa
void
Fif_PREFIXb
Fif_ENTRYPOINT(cdf_set_zvar_compression__,
               cdf_set_zvar_compression_,
               cdf_set_zvar_compression,
               CDF_SET_ZVAR_COMPRESSION)
(id, var_num, compress_type, compress_parms, status)
Int32     *id;          /* In: CDF identifier. */
Int32     *var_num;     /* In: CDF zVariable number. */
Int32     *compress_type;   /* In: zVariable's compression type. */
Int32     compress_parms[]; /* In: zVariable's compression parameters. */
Int32     *status;      /* Out: CDF status code. */
{
  long cParms[CDF_MAX_PARMS];
  int ix;

  for (ix = 0; ix < CDF_MAX_PARMS; ix++)
    cParms[ix] = (long) compress_parms[ix];

  *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id),
                                     zVAR_, (long) (*var_num - 1),
                            PUT_, zVAR_COMPRESSION_, (long) *compress_type,
                                                     cParms,
                            NULL_);
  return;
}

/******************************************************************************
*  CDF_set_zvar_padvalue.
******************************************************************************/

VISIBLE_PREFIX
Fif_PREFIXa
void
Fif_PREFIXb
Fif_ENTRYPOINT(cdf_set_zvar_padvalue__,
               cdf_set_zvar_padvalue_,
               cdf_set_zvar_padvalue,
               CDF_SET_ZVAR_PADVALUE)
(id, var_num, pad_value, status)
Int32     *id;          /* In: CDF identifier. */
Int32     *var_num;     /* In: CDF zVariable number. */
void      *pad_value;   /* In: zVariable's pad value. */
Int32     *status;      /* Out: CDF status code. */
{
  long dataType;

  *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id),
                                     zVAR_, (long) (*var_num - 1),
                            GET_, zVAR_DATATYPE_, &dataType,
                            NULL_);

  if (StatusBAD(*status)) return;

  *status = (Int32) CDFlib (PUT_, zVAR_PADVALUE_,
#if defined(Fif_DESCR)
                                          BOO(STRINGdataType(dataType),
                                              DESCRtoREF(pad_value),pad_value),
#else
                                          pad_value,
#endif

                            NULL_);
  return;
}

/******************************************************************************
*  CDF_set_zvar_sparserecords.
******************************************************************************/

VISIBLE_PREFIX
Fif_PREFIXa
void
Fif_PREFIXb
Fif_ENTRYPOINT(cdf_set_zvar_sparserecords__,
               cdf_set_zvar_sparserecords_,
               cdf_set_zvar_sparserecords,
               CDF_SET_ZVAR_SPARSERECORDS)
(id, var_num, sparse_records, status)
Int32     *id;          /* In: CDF identifier. */
Int32     *var_num;     /* In: CDF zVariable number. */
Int32     *sparse_records; /* In: zVariable's sparse records. */
Int32     *status;      /* Out: CDF status code. */
{

  *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id),
                                     zVAR_, (long) (*var_num - 1),
                            PUT_, zVAR_SPARSERECORDS_, (long) *sparse_records,
                            NULL_);
  return;
}

/******************************************************************************
*  CDF_set_zvar_allocrecs.
******************************************************************************/

VISIBLE_PREFIX
Fif_PREFIXa
void
Fif_PREFIXb
Fif_ENTRYPOINT(cdf_set_zvar_allocrecs__,
               cdf_set_zvar_allocrecs_,
               cdf_set_zvar_allocrecs,
               CDF_SET_ZVAR_ALLOCRECS)
(id, var_num, rec_num, status)
Int32     *id;          /* In: CDF identifier. */
Int32     *var_num;     /* In: CDF zVariable number. */
Int32     *rec_num;     /* In: zVariables's allocated record number. */
Int32     *status;      /* Out: CDF status code. */
{

  *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id),
                                     zVAR_, (long) (*var_num - 1),
                            PUT_, zVAR_ALLOCATERECS_, (long) *rec_num,
                            NULL_);
  return;
}

/******************************************************************************
*  CDF_set_zvar_allocblockrecs.
******************************************************************************/

VISIBLE_PREFIX
Fif_PREFIXa
void
Fif_PREFIXb
Fif_ENTRYPOINT(cdf_set_zvar_allocblockrecs__,
               cdf_set_zvar_allocblockrecs_,
               cdf_set_zvar_allocblockrecs,
               CDF_SET_ZVAR_ALLOCBLOCKRECS)
(id, var_num, start_rec, end_rec, status)
Int32     *id;          /* In: CDF identifier. */
Int32     *var_num;     /* In: CDF zVariable number. */
Int32     *start_rec;   /* In: zVariables's allocated block start record no. */
Int32     *end_rec;     /* In: zVariables's allocated block end record no. */
Int32     *status;      /* Out: CDF status code. */
{

  *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id),
                                     zVAR_, (long) (*var_num - 1),
                            PUT_, zVAR_ALLOCATEBLOCK_, (long) (*start_rec - 1),
                                                       (long) (*end_rec - 1),
                            NULL_);
  return;
}

/******************************************************************************
*  CDF_set_zvar_initialrecs.
******************************************************************************/

VISIBLE_PREFIX
Fif_PREFIXa
void
Fif_PREFIXb
Fif_ENTRYPOINT(cdf_set_zvar_initialrecs__,
               cdf_set_zvar_initialrecs_,
               cdf_set_zvar_initialrecs,
               CDF_SET_ZVAR_INITIALRECS)
(id, var_num, num_rec, status)
Int32     *id;          /* In: CDF identifier. */
Int32     *var_num;     /* In: CDF zVariable number. */
Int32     *num_rec;     /* In: zVariables's initially written records. */
Int32     *status;      /* Out: CDF status code. */
{

  *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id),
                                     zVAR_, (long) (*var_num - 1),
                            PUT_, zVAR_INITIALRECS_, (long) *num_rec,
                            NULL_);
  return;
}

/******************************************************************************
*  CDF_put_zvar_seqdata.
******************************************************************************/

VISIBLE_PREFIX
Fif_PREFIXa
void
Fif_PREFIXb
Fif_ENTRYPOINT(cdf_put_zvar_seqdata__,
               cdf_put_zvar_seqdata_,
               cdf_put_zvar_seqdata,
               CDF_PUT_ZVAR_SEQDATA)
(id, var_num, data, status)
Int32     *id;          /* In: CDF identifier. */
Int32     *var_num;     /* In: CDF zVariable number. */
void      *data;        /* In: CDF zVariable's data. */
Int32     *status;      /* Out: CDF status code. */
{
  long dataType;

  *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id),
                                     zVAR_, (long) (*var_num - 1),
                            GET_, zVAR_DATATYPE_, &dataType,
                            NULL_);

  if (StatusBAD(*status)) return;

  *status = (Int32) CDFlib (PUT_, zVAR_SEQDATA_,
#if defined(Fif_DESCR)
                                              BOO(STRINGdataType(dataType),
                                                  DESCRtoREF(data),data),
#else
                                              data,
#endif

                            NULL_);

  return;
}

/******************************************************************************
*  CDF_put_zvar_recorddata.
******************************************************************************/

VISIBLE_PREFIX
Fif_PREFIXa
void
Fif_PREFIXb
Fif_ENTRYPOINT(cdf_put_zvar_recorddata__,
               cdf_put_zvar_recorddata_,
               cdf_put_zvar_recorddata,
               CDF_PUT_ZVAR_RECORDDATA)
(id, var_num, rec_num, buffer, status)
Int32     *id;                  /* In: CDF identifier. */
Int32     *var_num;             /* In: CDF zVariable number. */
Int32     *rec_num;             /* In: CDF zVariable record number. */
void      *buffer;              /* In: zVariable's full record data. */
Int32     *status;              /* Out: CDF status code. */
{
  long numVars, varNums[1];

  numVars = 1;
  varNums[0] = (long) (*var_num - 1);

  *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id),
                                     zVARs_RECNUMBER_, (long) (*rec_num - 1),
                            PUT_, zVARs_RECDATA_, numVars, varNums, buffer,
                            NULL_);
  return;
}

/******************************************************************************
*  CDF_set_checksum.
******************************************************************************/

VISIBLE_PREFIX
Fif_PREFIXa
void
Fif_PREFIXb
Fif_ENTRYPOINT(cdf_set_checksum__,
               cdf_set_checksum_,
               cdf_set_checksum,
               CDF_SET_CHECKSUM)
(id, checksum, status)
Int32     *id;                  /* In: CDF identifier. */
Int32     *checksum;            /* In: CDF checksum. */
Int32     *status;              /* Out: CDF status code. */
{

  *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id),
                            PUT_, CDF_CHECKSUM_, (long) *checksum,
                            NULL_);
  
  return;
}

/******************************************************************************
*  CDF_verify_checksum.
******************************************************************************/

VISIBLE_PREFIX
Fif_PREFIXa
void
Fif_PREFIXb
Fif_ENTRYPOINT(cdf_verify_checksum__,
               cdf_verify_checksum_,
               cdf_verify_checksum,
               CDF_VERIFY_CHECKSUM)
(id, status)
Int32     *id;                  /* In: CDF identifier. */
Int32     *status;              /* Out: CDF status code. */
{

  *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id),
                            CONFIRM_, CDF_CHECKSUM_, 
                            NULL_);

  return;
}

/******************************************************************************
*  CDF_select_cdf.
******************************************************************************/

VISIBLE_PREFIX
Fif_PREFIXa
void
Fif_PREFIXb
Fif_ENTRYPOINT(cdf_select_cdf__,
               cdf_select_cdf_,
               cdf_select_cdf,
               CDF_SELECT_CDF)
(id, status)
Int32     *id;                  /* In: CDF identifier. */
Int32     *status;              /* Out: CDF status code. */
{

  *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id),
                            NULL_);

  return;
}

/******************************************************************************
*  CDF_delete_recordsforall.
******************************************************************************/

VISIBLE_PREFIX
Fif_PREFIXa
void
Fif_PREFIXb
Fif_ENTRYPOINT(cdf_delete_recordsforall__,
               cdf_delete_recordsforall_,
               cdf_delete_recordsforall,
               CDF_DELETE_RECORDSFORALL)
(id, startRec, endRec, status)
Int32     *id;                  /* In: CDF identifier. */
Int32     startRec;             /* In: Starting records to delete. */
Int32     endRec;               /* In: Ending records to delete. */
Int32     *status;              /* Out: CDF status code. */
{

  *status = CDFdeleteRecordsForAll (Int32ToCDFid(*id), startRec, endRec);

  return;
}

/******************************************************************************
*  CDF_get_leapsecondlastupdated.
******************************************************************************/

VISIBLE_PREFIX
Fif_PREFIXa
void
Fif_PREFIXb
Fif_ENTRYPOINT(cdf_get_leapsecondlastupdated__,
               cdf_get_leapsecondlastupdated_,
               cdf_get_leapsecondlastupdated,
               CDF_GET_LEAPSECONDLASTUPDATED)
(id, lastUpdated, status)
Int32     *id;                  /* In: CDF identifier. */
Int32     *lastUpdated;         /* Out: Last updated date for leap second. */
Int32     *status;              /* Out: CDF status code. */
{
  long lastUpdatedT;
  *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id),
                            GET_, CDF_LEAPSECONDLASTUPDATED_, &lastUpdatedT,
                            NULL_);
  if (StatusOK(*status)) *lastUpdated = (Int32) lastUpdatedT;
  return;
}

/******************************************************************************
*  CDF_set_leapsecondlastupdated.
******************************************************************************/

VISIBLE_PREFIX
Fif_PREFIXa
void
Fif_PREFIXb
Fif_ENTRYPOINT(cdf_set_leapsecondlastupdated__,
               cdf_set_leapsecondlastupdated_,
               cdf_set_leapsecondlastupdated,
               CDF_SET_LEAPSECONDLASTUPDATED)
(id, lastUpdated, status)
Int32     *id;                  /* In: CDF identifier. */
Int32     *lastUpdated;         /* In: last updated date for leap second. */
Int32     *status;              /* Out: CDF status code. */
{
  *status = (Int32) CDFlib (SELECT_, CDF_, Int32ToCDFid(*id),
                            PUT_, CDF_LEAPSECONDLASTUPDATED_,
                                  (long)*lastUpdated,
                            NULL_);
  return;
}

