/**********************************************************************
*
* 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.r4000.zip_mexcdf toolbox_mexnc_netcdf toolbox_pwd
共343个文件
m:259个
nc:35个
sh:10个
1.该资源内容由用户上传,如若侵权请联系客服进行举报
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
2.虚拟产品一经售出概不退款(资源遇到问题,请及时私信上传者)
版权申诉
5星 · 超过95%的资源 1 下载量 82 浏览量
2022-09-23
13:24:24
上传
评论
收藏 460KB ZIP 举报
温馨提示
Toolbox to read netcdf files on Matlab Install: javaaddpath([pwd /netcdfAll-4.2.jar ]) unzip( mexcdf.r4000.zip ) addpath ([pwd /mexcdf/mexnc ]) addpath ([pwd /mexcdf/snctools ])
资源推荐
资源详情
资源评论
收起资源包目录
mexcdf.r4000.zip_mexcdf toolbox_mexnc_netcdf toolbox_pwd (343个子文件)
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 12KB
ChangeLog 44KB
ChangeLog 18KB
SncCreds.class 755B
COPYING 262B
ecmf_20070122_pf_regular_ll_pt_320_pv_grid_simple.grib2 2KB
netcdf3.h 5KB
mexnc.h 5KB
netcdf2.h 786B
netcdf4.h 729B
varget.hdf 18KB
attget.hdf 16KB
fillvalue_scaling.hdf 9KB
temppres.hdf 8KB
varput.hdf 8KB
full.hdf 5KB
iscoordvar.hdf 5KB
empty.hdf 2KB
SncCreds.java 780B
mexnc_tmw.m 74KB
test_put_var_bad_param_datatype.m 54KB
test_get_var_bad_param_datatype.m 53KB
test_varput.m 25KB
mexnc.m 24KB
test_attput.m 23KB
test_nc_varget.m 23KB
test_nc_info.m 18KB
test_put_get_var_double.m 16KB
test_inq_var.m 15KB
test_varputg.m 15KB
test_nc_addvar.m 15KB
test_nc_varput.m 14KB
test_put_get_var_float.m 14KB
test_put_get_att.m 13KB
test_varput_1g.m 13KB
test_nc_addnewrecs.m 13KB
test_put_get_var_short.m 13KB
test_put_get_var_int.m 13KB
test_varput1.m 13KB
test_put_get_var_uchar.m 13KB
test_put_get_var_schar.m 13KB
test_def_var.m 13KB
nc_dump.m 13KB
test_nc_attget.m 12KB
nc_cf_grid_write_lat_lon_curvilinear_tutorial.m 12KB
test_copy_att.m 12KB
run_snctools_tests.m 11KB
nc_info_tmw.m 11KB
test_inq.m 11KB
test_put_get_var_text.m 11KB
test_def_dim.m 10KB
nc_varput_mexnc.m 10KB
test_nc_dump.m 9KB
test_deflate.m 9KB
test_nc_attput.m 9KB
test_nc_diff.m 8KB
test_inq_dim.m 8KB
test_nc_getbuffer.m 8KB
test_attcopy.m 8KB
test_inq_attid.m 8KB
test_del_att.m 8KB
test_redef_def_dim.m 8KB
test_create.m 7KB
test_nc_varput_neg.m 7KB
nc_addnewrecs.m 7KB
test_nc_varget_neg.m 7KB
test_chunking.m 7KB
snc_read_backend.m 7KB
nc_cat.m 7KB
test_rename_att.m 7KB
nc_attput_hdf4.m 6KB
test_nc_addrecs.m 6KB
test_inq_att.m 6KB
test_nc_getvarinfo.m 6KB
test_nc_getall.m 6KB
nc_addvar.m 6KB
nc_varget_tmw.m 6KB
nc_diff.m 6KB
nc_isatt.m 5KB
nc_cat_a.m 5KB
test_nc_isatt.m 5KB
mexcdf.m 5KB
test_nc_getlast.m 5KB
test_rename_var.m 5KB
test_nc_attget_neg.m 5KB
nc_varget_java.m 5KB
nc_attget_java.m 5KB
nc_info_hdf4.m 5KB
test_rename_dim.m 5KB
test_inq_attlen.m 5KB
test_nc_cat.m 5KB
共 343 条
- 1
- 2
- 3
- 4
资源评论
- 路飞的偶像2023-03-14实在是宝藏资源、宝藏分享者!感谢大佬~
Kinonoyomeo
- 粉丝: 74
- 资源: 1万+
下载权益
C知道特权
VIP文章
课程特权
开通VIP
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功