#include <stdio.h>#include <stdlib.h>#include <string.h>#include <netcdf.h>#include "nco_netcdf.h"#include "nco.h"#include "nco_cnf_typ.h"#include "nco_ctl.h"#include "nco_mmr.h"#include "nco_var_utl.h"Include dependency graph for nco_scl_utl.h:

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

Go to the source code of this file.
Functions | |
| var_sct * | scl_dbl_mk_var (const double val) |
| var_sct * | scl_mk_var (val_unn val, const nc_type val_typ) |
| var_sct * | scl_ptr_mk_var (const ptr_unn val_ptr_unn, const nc_type val_typ) |
| double | ptr_unn_2_scl_dbl (const ptr_unn val, const nc_type type) |
| scv_sct | ptr_unn_2_scv (const nc_type type, ptr_unn val) |
|
||||||||||||
|
Definition at line 99 of file nco_scl_utl.c. References ptr_unn::dp, EXIT_FAILURE, NC_DOUBLE, nco_exit(), nco_free(), nco_malloc(), nco_typ_lng(), nco_val_cnf_typ(), prg_nm_get(), type, and ptr_unn::vp. Referenced by nco_var_pck(). 00101 { 00102 /* Purpose: Return first element of NCO variable converted to a scalar double */ 00103 00104 double scl_dbl; /* [sct] Double precision value of scale_factor */ 00105 00106 ptr_unn ptr_unn_scl_dbl; /* [unn] Pointer union to double precision value of first element */ 00107 00108 /* Variable must be in memory already */ 00109 if(val.vp == NULL){ 00110 (void)fprintf(stdout,"%s: ERROR ptr_unn_2_scl_dbl() called with empty val.vp\n",prg_nm_get()); 00111 nco_exit(EXIT_FAILURE); 00112 } /* endif */ 00113 00114 /* Valid memory address exists */ 00115 ptr_unn_scl_dbl.vp=(void *)nco_malloc(nco_typ_lng(NC_DOUBLE)); /* [unn] Pointer union to double precision value of first element */ 00116 (void)nco_val_cnf_typ(type,val,NC_DOUBLE,ptr_unn_scl_dbl); 00117 scl_dbl=ptr_unn_scl_dbl.dp[0]; 00118 ptr_unn_scl_dbl.vp=nco_free(ptr_unn_scl_dbl.vp); 00119 00120 return scl_dbl; 00121 00122 } /* end ptr_unn_2_scl_dbl() */
|
|
||||||||||||
|
Definition at line 126 of file nco_scl_utl.c. References val_unn::b, ptr_unn::bp, cast_void_nctype(), val_unn::d, ptr_unn::dp, val_unn::f, ptr_unn::fp, val_unn::l, ptr_unn::lp, NC_BYTE, NC_CHAR, NC_DOUBLE, NC_FLOAT, NC_INT, NC_SHORT, nco_dfl_case_nc_type_err(), val_unn::s, ptr_unn::sp, scv_sct::type, type, and scv_sct::val. Referenced by nco_var_upk(). 00128 { 00129 /* Purpose: Convert ptr_unn to scalar value structure 00130 Assumes that val is initially cast to void 00131 Note does not convert cp (strings) as these are not handled by scv_sct 00132 NB: netCDF attributes may contain multiple values 00133 Only FIRST value in memory block is converted */ 00134 00135 scv_sct scv; 00136 (void)cast_void_nctype(type,&val); 00137 switch(type){ 00138 case NC_FLOAT: scv.val.f=*val.fp; break; 00139 case NC_DOUBLE: scv.val.d =*val.dp; break; 00140 case NC_INT: scv.val.l =*val.lp; break; 00141 case NC_SHORT: scv.val.s=*val.sp; break; 00142 case NC_BYTE: scv.val.b =*val.bp; break; 00143 case NC_CHAR: break; /* Do nothing */ 00144 default: nco_dfl_case_nc_type_err(); break; 00145 } /* end switch */ 00146 scv.type=type; 00147 /* Do not uncast pointer as we are working with a copy */ 00148 return scv; 00149 } /* end ptr_unn_2_scv */
|
|
|
Definition at line 13 of file nco_scl_utl.c. References var_sct_tag::nbr_dim, NC_DOUBLE, nco_malloc(), nco_typ_lng(), var_sct_tag::nm, var_sct_tag::type, var_sct_tag::val, var_dfl_set(), and ptr_unn::vp. 00014 { 00015 /* Purpose: Convert scalar double into netCDF variable 00016 Routine duplicates most functions of nco_var_fll() 00017 Both functions should share as much initialization code as possible */ 00018 var_sct *var; 00019 00020 var=(var_sct *)nco_malloc(sizeof(var_sct)); 00021 00022 /* Set defaults */ 00023 (void)var_dfl_set(var); /* [fnc] Set defaults for each member of variable structure */ 00024 00025 /* Overwrite defaults with values appropriate for artificial variable */ 00026 var->nm=(char *)strdup("Internally generated variable"); 00027 var->nbr_dim=0; 00028 var->type=NC_DOUBLE; 00029 var->val.vp=(void *)nco_malloc(nco_typ_lng(var->type)); 00030 (void)memcpy((void *)var->val.vp,(const void *)(&val),nco_typ_lng(var->type)); 00031 00032 return var; 00033 } /* end scl_dbl_mk_var() */
|
|
||||||||||||
|
Definition at line 37 of file nco_scl_utl.c. References val_unn::b, ptr_unn::bp, val_unn::c, cast_nctype_void(), ptr_unn::cp, val_unn::d, ptr_unn::dp, val_unn::f, ptr_unn::fp, val_unn::l, ptr_unn::lp, NC_BYTE, NC_CHAR, NC_DOUBLE, NC_FLOAT, NC_INT, NC_SHORT, nco_dfl_case_nc_type_err(), val_unn::s, scl_ptr_mk_var(), and ptr_unn::sp. Referenced by main(), nco_var_dfn(), and nco_var_pck(). 00039 { 00040 /* Purpose: Turn scalar value of any type into NCO variable 00041 Routine is just a wrapper for scl_ptr_mk_var() 00042 This routine creates the void * argument needed for scl_ptr_mk_var(), 00043 calls, scl_ptr_mk_var(), then passes back the result */ 00044 00045 var_sct *var; 00046 ptr_unn val_ptr_unn; /* [ptr] void pointer to value */ 00047 00048 switch(val_typ){ 00049 case NC_FLOAT: val_ptr_unn.fp=&val.f; break; 00050 case NC_DOUBLE: val_ptr_unn.dp=&val.d; break; 00051 case NC_INT: val_ptr_unn.lp=&val.l; break; 00052 case NC_SHORT: val_ptr_unn.sp=&val.s; break; 00053 case NC_CHAR: val_ptr_unn.cp=&val.c; break; 00054 case NC_BYTE: val_ptr_unn.bp=&val.b; break; 00055 default: nco_dfl_case_nc_type_err(); break; 00056 } /* end switch */ 00057 00058 /* Un-typecast pointer to values after access */ 00059 (void)cast_nctype_void(val_typ,&val_ptr_unn); 00060 00061 var=scl_ptr_mk_var(val_ptr_unn,val_typ); 00062 00063 return var; 00064 } /* end scl_mk_var() */
|
|
||||||||||||
|
Definition at line 68 of file nco_scl_utl.c. References var_sct_tag::nbr_dim, nco_malloc(), nco_typ_lng(), var_sct_tag::nm, var_sct_tag::type, var_sct_tag::val, var_dfl_set(), and ptr_unn::vp. Referenced by nco_var_pck(), and scl_mk_var(). 00070 { 00071 /* Purpose: Convert void pointer to scalar of any type into NCO variable 00072 Routine duplicates many functions of nco_var_fll() 00073 Both functions should share as much initialization code as possible */ 00074 var_sct *var; 00075 00076 var=(var_sct *)nco_malloc(sizeof(var_sct)); 00077 00078 /* Set defaults */ 00079 (void)var_dfl_set(var); /* [fnc] Set defaults for each member of variable structure */ 00080 00081 /* Overwrite defaults with values appropriate for artificial variable */ 00082 var->nm=(char *)strdup("Internally generated variable"); 00083 var->nbr_dim=0; 00084 var->type=val_typ; 00085 /* Allocate new space here so that variable can eventually be deleted 00086 and associated memory free()'d */ 00087 /* free(val_ptr_unn.vp) is unpredictable since val_ptr_unn may point to constant data, e.g., 00088 a constant in scl_mk_var */ 00089 var->val.vp=(void *)nco_malloc(nco_typ_lng(var->type)); 00090 00091 /* Copy value into variable structure */ 00092 (void)memcpy((void *)var->val.vp,val_ptr_unn.vp,nco_typ_lng(var->type)); 00093 00094 return var; 00095 } /* end scl_ptr_mk_var() */
|
1.4.4