Logo Search packages:      
Sourcecode: nco version File versions  Download package


/* $Header: /cvsroot/nco/nco/src/nco/nco_cnv_csm.c,v 1.14 2004/02/13 06:33:50 zender Exp $ */

/* Purpose: CCSM conventions */

/* Copyright (C) 1995--2004 Charlie Zender
   This software may be modified and/or re-distributed under the terms of the GNU General Public License (GPL) Version 2
   See http://www.gnu.ai.mit.edu/copyleft/gpl.html for full license text */

#include "nco_cnv_csm.h" /* CCSM conventions */

bool /* O [flg] File obeys CCSM conventions */
nco_ncar_csm_inq /* O [fnc] Check if file obeys CCSM conventions */
(const int nc_id) /* I [id] netCDF file ID */
  /* Purpose: Check if file adheres to NCAR CCSM history tape format */

  bool NCAR_CCSM=False;

  char *att_val;

  char cnv_sng[]="Conventions"; /* Unidata standard string */
  int rcd; /* [rcd] Return code */
  long att_sz;

  nc_type att_typ;

  /* Look for signature of an NCAR CCSM format file */

  if(rcd == NC_NOERR && att_typ == NC_CHAR){
    /* Add one for NULL byte */
    att_val=(char *)nco_malloc(att_sz*nco_typ_lng(att_typ)+1);
    /* NUL-terminate convention attribute before using strcmp() */
    /* CCM3, CCSM1 conventions */
    if(strstr(att_val,"NCAR-CSM") != NULL) NCAR_CCSM=True; /* Backwards compatibility */
    /* Climate-Forecast conventions */
    if(strstr(att_val,"CF-1.0") != NULL) NCAR_CCSM=True; /* NB: Not fully implemented TODO nco145 */
    if(NCAR_CCSM && dbg_lvl_get() > 0) (void)fprintf(stderr,"%s: CONVENTION File convention is %s\n",prg_nm_get(),att_val);
    att_val=(char *)nco_free(att_val);
  } /* endif */

  return NCAR_CCSM;
} /* end nco_ncar_csm_inq */

nco_ncar_csm_date /* [fnc] Fix date variable in averaged CCSM files */
(const int nc_id, /* I [id] netCDF file ID */
 X_CST_PTR_CST_PTR_Y(var_sct,var), /* I/O [sct] Variables in output file */
 const int nbr_var) /* I [nbr] Number of variables in list */
  /* Purpose: Fix date variable in averaged CCSM files */
  char wrn_sng[1000];

  int date_idx;
  int idx;
  int rcd=NC_NOERR; /* [rcd] Return code */
  int time_idx;
  long day;

  int nbdate_id;
  nco_long nbdate;
  nco_long date;
  (void)sprintf(wrn_sng,"Most, but not all, CCSM files which are in CCM format contain the fields \"nbdate\", \"time\", and \"date\". When the \"date\" field is present but either \"nbdate\" or \"time\" is missing, then %s is unable to construct a meaningful average \"date\" to store in the output file. Therefore the \"date\" variable in your output file may be meaningless.\n",prg_nm_get());

  /* Find date variable (NC_INT: current date as 6 digit integer (YYMMDD)) */
    if(!strcmp(var[idx]->nm,"date")) break;
  } /* end loop over idx */
  if(idx == nbr_var) return; else date_idx=idx;
  if(var[date_idx]->type != NC_INT) return;
  /* Find scalar nbdate variable (NC_INT: base date date as 6 digit integer (YYMMDD)) */
  if(rcd != NC_NOERR){
    (void)fprintf(stderr,"%s: WARNING NCAR CCSM convention file output variable list contains \"date\" but not \"nbdate\"\n",prg_nm_get());
    (void)fprintf(stderr,"%s: %s",prg_nm_get(),wrn_sng);
  } /* endif */
  /* Find time variable (NC_DOUBLE: current day) */
    if(!strcmp(var[idx]->nm,"time")) break;
  } /* end loop over idx */
  if(idx == nbr_var){
    (void)fprintf(stderr,"%s: WARNING NCAR CCSM convention file output variable list contains \"date\" but not \"time\"\n",prg_nm_get());
    (void)fprintf(stderr,"%s: %s",prg_nm_get(),wrn_sng);
  } /* endif */
  /* Assign current day to averaged day number */
  /* Recompute date variable based on new (averaged) day number */
  if(var[date_idx]->val.lp != NULL) return; else var[date_idx]->val.lp[0]=date;
} /* end nco_ncar_csm_date */

Generated by  Doxygen 1.6.0   Back to index