nco/nco_cnv_csm.h File Reference

#include <stdio.h>
#include <string.h>
#include <netcdf.h>
#include "nco_netcdf.h"
#include "nco.h"
#include "nco_cln_utl.h"
#include "nco_mmr.h"

Include dependency graph for nco_cnv_csm.h:

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

Go to the source code of this file.

Functions

bool nco_cnv_ccm_ccsm_cf_inq (const int nc_id)
void nco_cnv_ccm_ccsm_cf_date (const int nc_id, X_CST_PTR_CST_PTR_Y(var_sct, var), const int nbr_var)


Function Documentation

void nco_cnv_ccm_ccsm_cf_date const int  nc_id,
X_CST_PTR_CST_PTR_Y(var_sct, var)  ,
const int  nbr_var
 

Definition at line 56 of file nco_cnv_csm.c.

References var_sct_tag::nc_id, NC_INT, NC_NOERR, nco_get_var1(), nco_inq_varid_flg(), nco_newdate(), var_sct_tag::nm, and prg_nm_get().

Referenced by main().

00059 {
00060   /* Purpose: Fix date variable in averaged CCM/CCSM/CF files */
00061   char wrn_sng[1000];
00062 
00063   int date_idx;
00064   int idx;
00065   int rcd=NC_NOERR; /* [rcd] Return code */
00066   int time_idx;
00067   
00068   long day;
00069 
00070   int nbdate_id;
00071   
00072   nco_int nbdate;
00073   nco_int date;
00074   
00075   (void)sprintf(wrn_sng,"Most, but not all, CCM/CCSM/CF 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());
00076 
00077   /* Find date variable (NC_INT: current date as 6 digit integer (YYMMDD)) */
00078   for(idx=0;idx<nbr_var;idx++){
00079     if(!strcmp(var[idx]->nm,"date")) break;
00080   } /* end loop over idx */
00081   if(idx == nbr_var) return; else date_idx=idx;
00082   if(var[date_idx]->type != NC_INT) return;
00083   
00084   /* Find scalar nbdate variable (NC_INT: base date date as 6 digit integer (YYMMDD)) */
00085   rcd=nco_inq_varid_flg(nc_id,"nbdate",&nbdate_id);
00086   if(rcd != NC_NOERR){
00087     (void)fprintf(stderr,"%s: WARNING CCM/CCSM/CF convention file output variable list contains \"date\" but not \"nbdate\"\n",prg_nm_get());
00088     (void)fprintf(stderr,"%s: %s",prg_nm_get(),wrn_sng);
00089     return;
00090   } /* endif */
00091 
00092   { /* begin potential OpenMP critical */
00093     /* Block is critical/thread-safe for identical/distinct in_id's */
00094     (void)nco_get_var1(nc_id,nbdate_id,0L,&nbdate,NC_INT);
00095   } /* end potential OpenMP critical */
00096   
00097   /* Find time variable (NC_DOUBLE: current day) */
00098   for(idx=0;idx<nbr_var;idx++){
00099     if(!strcmp(var[idx]->nm,"time")) break;
00100   } /* end loop over idx */
00101   if(idx == nbr_var){
00102     (void)fprintf(stderr,"%s: WARNING CCM/CCSM/CF convention file output variable list contains \"date\" but not \"time\"\n",prg_nm_get());
00103     (void)fprintf(stderr,"%s: %s",prg_nm_get(),wrn_sng);
00104     return;
00105   }else{
00106     time_idx=idx;
00107   } /* endif */
00108   
00109   /* Assign current day to averaged day number */
00110   day=(long)(var[time_idx]->val.dp[0]);
00111   
00112   /* Recompute date variable based on new (averaged) day number */
00113 #ifdef USE_FORTRAN_ARITHMETIC
00114   date=FORTRAN_newdate(&nbdate,&day);
00115 #else /* !USE_FORTRAN_ARITHMETIC */
00116   date=nco_newdate(nbdate,day);
00117 #endif /* !USE_FORTRAN_ARITHMETIC */
00118   if(var[date_idx]->val.lp != NULL) return; else var[date_idx]->val.lp[0]=date;
00119   
00120   return; /* 20050109: fxm added return to void function to squelch erroneous gcc-3.4.2 warning */ 
00121 } /* end nco_cnv_ccm_ccsm_cf_date */

bool nco_cnv_ccm_ccsm_cf_inq const int  nc_id  ) 
 

Definition at line 13 of file nco_cnv_csm.c.

References dbg_lvl_get(), False, NC_CHAR, NC_GLOBAL, var_sct_tag::nc_id, NC_NOERR, nco_bool, nco_free(), nco_get_att(), nco_inq_att_flg(), nco_malloc(), nco_typ_lng(), prg_nm_get(), and True.

Referenced by main().

00014 {
00015   /* Purpose: Check if file adheres to CCM/CCSM/CF history tape format */
00016 
00017   nco_bool CNV_CCM_CCSM_CF=False;
00018 
00019   char *att_val;
00020 
00021   char cnv_sng[]="Conventions"; /* Unidata standard string */
00022   
00023   int rcd; /* [rcd] Return code */
00024   
00025   long att_sz;
00026 
00027   nc_type att_typ;
00028 
00029   /* Look for signature of an CCM/CCSM/CF format file */
00030   rcd=nco_inq_att_flg(nc_id,NC_GLOBAL,cnv_sng,&att_typ,&att_sz);
00031 
00032   if(rcd == NC_NOERR && att_typ == NC_CHAR){
00033     /* Add one for NUL byte */
00034     att_val=(char *)nco_malloc(att_sz*nco_typ_lng(att_typ)+1);
00035     (void)nco_get_att(nc_id,NC_GLOBAL,cnv_sng,att_val,att_typ);
00036     /* NUL-terminate convention attribute before using strcmp() */
00037     att_val[att_sz]='\0';
00038     /* CCM3, CCSM1 conventions */
00039     if(strstr(att_val,"NCAR-CSM") != NULL) CNV_CCM_CCSM_CF=True; /* Backwards compatibility */
00040     /* Climate-Forecast conventions */
00041     if(strstr(att_val,"CF-1.0") != NULL) CNV_CCM_CCSM_CF=True; /* NB: Not fully implemented TODO nco145 */
00042     if(CNV_CCM_CCSM_CF && dbg_lvl_get() > 0){
00043       (void)fprintf(stderr,"%s: CONVENTION File Convention attribute is \"%s\".",prg_nm_get(),att_val);
00044       if(dbg_lvl_get() > 1) (void)fprintf(stderr," NCO has a unified (but incomplete) treatment of many related (official and unoffical) conventions such as CCM, CCSM, and CF. As part of adhering to this convention, NCO implements variable-specific exceptions in certain operators, e.g., ncbo will not subtract variables named \"date\" or \"gw\". For a full list of exceptions, see the manual http://nco.sf.net/nco.html#CF");
00045       (void)fprintf(stderr,"\n");
00046     } /* endif dbg */
00047     att_val=(char *)nco_free(att_val);
00048   } /* endif */
00049 
00050   return CNV_CCM_CCSM_CF;
00051   
00052 } /* end nco_cnv_ccm_ccsm_cf_inq */


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