/**********************************************************************
*
* netcdf3.c
*
* This file contains code to handle the mexfile interface to NetCDF-3
* API calls.
*
*********************************************************************/
/*
* $Id: netcdf3.c 2828 2010-01-15 14:48:55Z johnevans007 $
* */
# include <ctype.h>
# include <errno.h>
# include <stdio.h>
# include <stdlib.h>
# include <string.h>
# include "netcdf.h"
# include "mex.h"
# include "mexnc.h"
# include "netcdf3.h"
/*
* Let each function use this over and over again.
* */
static char error_message[1000];
/*
* DETERMINE_VARM_OUTPUT_SIZE
*
* The get_varm and put_varm routines are unusual in that the size of
* the resulting output array do not necessarily match what that of
* the nc_count_coord array.
*
* The size of each edge depends upon computing the ratio of the two
* smallest edges of the imap vector. It has to be that way, if you think
* about the definition of the imap vector. For example, suppose that the
* netcdf variable is 8x6x4 in size and that the imap vector is [24 4 1].
* This trivially maps the output into an 8x6x4 output array, but it's a
* good example, nevertheless.
*
* There are 192 elements to be retrieved, but the first imap element of
* 24 means that there is a distance of
* So the output size is [8 6 4].
*
* As a second example, suppose we have the same 8x6x4 array, but the
* imap vector is [1 8 48].
*
* Ex. #2 NetCDF size = [5 4 3 2].
* Want the trivial matlab size of [5 4 3 2].
* Think in terms of the transpose, [2 3 4 5].
* Imap vector is [1 5 20 60]
*
* Not sure why this works, exactly. It makes sense for the trivial
* mapping, but hard to figure otherwise.
*
* */
void determine_varm_output_size (
int ndims,
int num_requested_elements,
size_t *nc_count_coord,
ptrdiff_t *nc_stride_coord,
ptrdiff_t *nc_imap_coord,
int *result_size )
{
/*
* Loop index
* */
int j, k;
char error_message[1000];
/*
* If an element in this array is flagged, it means that we
* have already figured its contribution.
* */
int still_unused[MAX_NC_DIMS];
/*
* Keeps track of the largest remaining imap coordinate for
* each dimension.
* */
ptrdiff_t max_imap_element_size;
ptrdiff_t max_imap_element_index;
/*
* Initialize the flag array.
* */
for ( j = 0; j < MAX_NC_DIMS; ++j ) {
still_unused[j] = 1;
}
/*
* For each dimension, figure the contribution.
* */
for ( j = 0; j < ndims; ++j ) {
/*
* Find the largest remaining imap element.
* */
max_imap_element_size = -1;
for ( k = 0; k < ndims; ++k ) {
if ( (nc_imap_coord[k] > max_imap_element_size) && ( still_unused[k] ) ) {
max_imap_element_index = k;
max_imap_element_size = nc_imap_coord[k];
}
}
/*
* Figure the contribution for this dimension.
* Remember to reverse the order, otherwise the row-major order
* and column-major order issue will get us.:W
* */
result_size[j] = num_requested_elements / nc_imap_coord [ max_imap_element_index ];
/*
* Reduce the dimensionality.
* */
num_requested_elements = nc_imap_coord [ max_imap_element_index ];
/*
* We are done with this imap coordinate. Mark it as used.
* */
still_unused[max_imap_element_index] = 0;
}
/*
* Check that no elements in result_size are non-positive.
* That can crash matlab hard.
* */
for ( j = 0; j < ndims; ++j ) {
if ( result_size[j] < 1 ) {
sprintf ( error_message, "Requested data extent is invalid.\n\n" );
mexPrintf ( error_message );
mexPrintf ( "count " );
for ( j = 0; j < ndims; ++j ) {
printf ( "[%d]", nc_count_coord[j] );
}
mexPrintf ( "\n\n" );
mexPrintf ( "stride " );
for ( j = 0; j < ndims; ++j ) {
printf ( "[%d]", nc_stride_coord[j] );
}
mexPrintf ( "\n\n" );
mexPrintf ( "imap " );
for ( j = 0; j < ndims; ++j ) {
printf ( "[%d]", nc_imap_coord[j] );
}
mexPrintf ( "\n\n" );
mexPrintf ( "result_size " );
for ( j = 0; j < ndims; ++j ) {
printf ( "[%d]", result_size[j] );
}
mexPrintf ( "\n\n" );
mexErrMsgTxt ( "\n\n" );
}
}
}
/***********************************************************************
*
* HANDLE_NC_ABORT
*
* code for handling the nc_abort routine.
*
* PARAMETERS:
* nlhs:
* number of output arguments defined in matlab
* plhs:
* Array of output matlab arrays.
* plhs[0] = return status of the nc_abort function call
* nrhs:
* number of input arguments defined in matlab
* prhs:
* Array of input matlab arrays.
* prhs[0] = 'ABORT'
* prhs[1] = file ID (ncid) of the netcdf file
* nc_op:
* Pointer to the current mexnc operation structure.
*
**********************************************************************/
void handle_nc_abort
(
int nlhs,
mxArray *plhs[],
int nrhs,
const mxArray *prhs[],
op *nc_op
)
{
/*
* Pointer shortcut to matrix data.
* */
double *pr;
/*
* file and variable IDs used in nc_copy_att
* */
int ncid;
/*
* Return status from netcdf operation.
* */
int status;
/*
* Make sure that the inputs are the right type.
* */
check_numeric_argument_type ( prhs, nc_op->opname, 1 );
pr = mxGetData ( prhs[1] );
ncid = (int)(pr[0]);
status = nc_abort(ncid);
plhs[0] = mexncCreateDoubleScalar(status);
return;
}
/***********************************************************************
*
* HANDLE_NC_CLOSE
*
* code for handling the nc_close routine.
*
* PARAMETERS:
* nlhs:
* number of output arguments defined in matlab
* plhs:
* Array of output matlab arrays.
* plhs[0] = the return status of the nc_close function call
* nrhs:
* number of input arguments defined in matlab
* prhs:
* Array of input matlab arrays.
* prhs[0] = 'INQ_CLOSE'
* prhs[1] = file ID (ncid) of the netcdf file
* nc_op:
* Pointer to the current mexnc operation structure.
*
**********************************************************************/
void handle_nc_close
(
int nlhs,
mxArray *plhs[],
int nrhs,
const mxArray *prhs[],
op *nc_op
)
{
/*
* Pointer shortcut to matrix data.
* */
double *pr;
/*
* file and variable IDs used in nc_copy_att
* */
int ncid;
/*
* Return status from netcdf operation.
* */
int status;
/*
* Make sure that the inputs are the right type.
* */
check_numeric_argument_type ( prhs, nc_op->opname, 1 );
/*
* Unpack the parameters.
* */
pr = mxGetData ( prhs[1] );
ncid = (int)(pr[0]);
status = nc_close(ncid);
plhs[0] = mexncCreateDoubleScalar ( status );
return;
}
/***********************************************************************
*
* HANDLE_COPY_ATT:
*
* code for handling the nc_copy_att routine.
*
* PARAMETERS:
* nlhs:
* number of output arguments defined in matlab
* plhs:
* Array of output matlab arrays. The return status of the
* nc_copy_att function call is placed into plhs[0].
* nrhs:
* numbe
没有合适的资源?快使用搜索试试~ 我知道了~
mexcdf.r2859.zip_matlab 2009b_matlab isvar_matlab r2009 mexcdf_m
共249个文件
m:199个
nc:16个
sh:10个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
0 下载量 100 浏览量
2022-09-24
01:48:25
上传
评论
收藏 334KB ZIP 举报
温馨提示
Mexcdf 格式文件的Matlab工具包,支持 Matlab 2009b 的最新版本
资源推荐
资源详情
资源评论
收起资源包目录
mexcdf.r2859.zip_matlab 2009b_matlab isvar_matlab r2009 mexcdf_m (249个子文件)
AUTHORS 109B
mexopts.R2008a.bat 3KB
mexopts.R2008a.win64.bat 3KB
mexopts.R14sp1.bat 2KB
mexopts.R13.bat 2KB
netcdf3.c 136KB
netcdf2.c 43KB
mexgateway.c 27KB
common.c 25KB
netcdf4.c 9KB
ChangeLog 24KB
ChangeLog 16KB
COPYING 262B
netcdf3.h 5KB
mexnc.h 5KB
netcdf2.h 786B
netcdf4.h 510B
mexnc_tmw.m 73KB
test_put_var_bad_param_datatype.m 54KB
test_get_var_bad_param_datatype.m 53KB
mexnc.m 26KB
test_nc_varput.m 26KB
test_attput.m 25KB
test_varput.m 21KB
test_varputg.m 19KB
test_nc_addnewrecs.m 18KB
test_nc_addvar.m 16KB
test_put_get_var_double.m 16KB
test_inq_var.m 15KB
test_put_get_var_float.m 14KB
test_put_get_att.m 13KB
test_varput_1g.m 13KB
test_put_get_var_short.m 13KB
test_put_get_var_int.m 13KB
test_put_get_var_uchar.m 13KB
test_put_get_var_schar.m 13KB
nc_varget.m 13KB
test_varput1.m 13KB
nc_varput.m 12KB
test_nc_varget.m 12KB
test_nc_getdiminfo.m 11KB
nc_add_recs.m 11KB
test_inq.m 11KB
test_nc_attget.m 11KB
test_put_get_var_text.m 10KB
nc_varget_java.m 10KB
test_nc_archive_buffer.m 10KB
test_deflate.m 9KB
test_nc_add_recs.m 9KB
test_def_dim.m 9KB
nc_addnewrecs.m 9KB
test_nc_diff.m 9KB
test_nc_add_dimension.m 8KB
test_inq_dim.m 8KB
test_inq_attid.m 8KB
test_nc_getvarinfo.m 8KB
nc_addvar.m 8KB
test_redef_def_dim.m 8KB
test_nc_getbuffer.m 8KB
test_attcopy.m 7KB
test_chunking.m 7KB
test_create.m 7KB
nc_varget_tmw.m 7KB
test_rename_att.m 7KB
test_def_var.m 6KB
test_inq_att.m 6KB
test_copy_att.m 6KB
nc_diff.m 6KB
test_nc_getall.m 6KB
test_nc_getlast.m 6KB
nc_getbuffer.m 5KB
nc_info.m 5KB
test_del_att.m 5KB
nc_cat_a.m 5KB
mexcdf.m 5KB
test_rename_var.m 5KB
test_dimdef.m 5KB
test_inq_attlen.m 5KB
test_sync.m 5KB
test_nc_varrename.m 5KB
test_rename_dim.m 5KB
test_nc_isvar.m 5KB
test_nc_addhist.m 5KB
create_test_ncfile.m 5KB
test__create.m 5KB
test_nc_attput.m 5KB
nc_dump.m 5KB
test_get_var1_text.m 5KB
test_snctools.m 5KB
test_inq_atttype.m 4KB
nc_attget.m 4KB
test_diminq.m 4KB
test_attrename.m 4KB
nc_varput_tmw.m 4KB
test_mexnc.m 4KB
nc_getall.m 4KB
test_inquire.m 4KB
test_inq_varid.m 4KB
test_varinq.m 4KB
test_dimrename.m 4KB
共 249 条
- 1
- 2
- 3
资源评论
钱亚锋
- 粉丝: 86
- 资源: 1万+
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功