7 #define RMISS -9.9999e+30 11 #define MIN(a,b) ((a)<(b) ? (a) : (b)) 13 static int32_t ERROR_SUPPRESS = 0;
15 #define CHECK_ERROR(func) \ 17 int status_ = (func); \ 18 if (status_ != NC_NOERR) { \ 19 if ( ! ERROR_SUPPRESS ) { \ 20 fprintf(stderr, "Error: at l%d in %s\n", __LINE__, __FILE__); \ 21 fprintf(stderr, " %s\n", nc_strerror(status_)); \ 29 #define CHECK_PNC_ERROR(func) \ 31 int status_ = (func); \ 32 if (status_ != NC_NOERR) { \ 33 if ( ! ERROR_SUPPRESS ) { \ 34 fprintf(stderr, "Error: at l%d in %s\n", __LINE__, __FILE__); \ 35 fprintf(stderr, " %s\n", ncmpi_strerror(status_)); \ 41 #define CHECK_PNC_ERROR(func) \ 43 fprintf(stderr, "pnetCDF is necessary for shared_mode\n"); \ 44 fprintf(stderr, "Please re-compile with pnetCDF\n"); \ 47 #define ncmpi_inq_attid(a,b,c,d) NC2_ERR 48 #define ncmpi_inq_varid(a,b,c) NC2_ERR 49 #define ncmpi_inq_dimid(a,b,c) NC2_ERR 52 #define NCTYPE2TYPE(nctype, type) \ 62 type = File_INTEGER2; \ 65 fprintf(stderr, "unsupported data type: %d\n", xtype); \ 70 #define TYPE2NCTYPE(type, nctype) \ 80 fprintf(stderr, "unsupported data type: %d\n", xtype); \ 86 #define DEFAULT_DEFLATE_LEVEL 2 92 #if defined(NETCDF3) || defined(PNETCDF) 122 #define VAR_MAX 40960 125 static int nfile = 0;
143 fprintf(stderr,
"exceed max number of file limit\n");
148 strcpy(_fname, fname);
149 if (fname[len-3] !=
'.' || fname[len-2] !=
'n' || fname[len-1] !=
'c' )
150 strcat(_fname,
".nc");
152 if ( comm == MPI_COMM_NULL || comm == MPI_COMM_SELF )
160 CHECK_PNC_ERROR( ncmpi_open(comm, _fname, NC_NOWRITE, MPI_INFO_NULL, &ncid) )
166 CHECK_PNC_ERROR( ncmpi_create(comm, _fname, NC_CLOBBER|NC_64BIT_OFFSET, MPI_INFO_NULL, &ncid) )
169 CHECK_ERROR( nc_create(_fname, NC_CLOBBER|NC_64BIT_OFFSET, &ncid) )
171 CHECK_ERROR( nc_create(_fname, NC_CLOBBER|NC_NETCDF4, &ncid) )
176 CHECK_PNC_ERROR( ncmpi_open(comm, _fname, NC_WRITE, MPI_INFO_NULL, &ncid) )
181 fprintf(stderr,
"invalid mode type\n");
186 files[nfile]->
ncid = ncid;
188 #if defined(NETCDF3) || defined(PNETCDF) 190 files[nfile]->defmode = 1;
192 files[nfile]->defmode = 0;
195 strcpy(files[nfile]->fname, fname);
207 if ( strcmp(filetype,
"netcdf") != 0 )
return SUCCESS_CODE;
209 if ( strcmp(key,
"deflate_level") == 0 ) {
227 int dimids[
MAX_RANK], tdim, uldims[NC_MAX_DIMS];
228 char name[NC_MAX_NAME+1];
233 ERROR_SUPPRESS = suppress;
236 ncid = files[fid]->
ncid;
237 if ( files[fid]->shared_mode )
245 strcpy(dinfo->
varname, varname);
246 if ( files[fid]->shared_mode ) {
250 buf = (
char*) malloc(l+1);
258 buf = (
char*) malloc(l+1);
261 dinfo->
units[i] = buf[i];
262 dinfo->
units[i] =
'\0';
280 CHECK_ERROR( nc_inq_attlen (ncid, varid,
"long_name", &l) )
281 buf = (
char*) malloc(l+1);
282 CHECK_ERROR( nc_get_att_text(ncid, varid,
"long_name", buf) )
288 CHECK_ERROR( nc_inq_attlen (ncid, varid,
"units", &l) )
289 buf = (
char*) malloc(l+1);
290 CHECK_ERROR( nc_get_att_text(ncid, varid,
"units", buf) )
292 dinfo->
units[i] = buf[i];
293 dinfo->
units[i] =
'\0';
300 CHECK_ERROR( nc_inq_vardimid(ncid, varid, dimids) )
310 for ( i=0; i<n; i++ ) {
311 if ( uldims[i] == dimids[0] ) {
317 fprintf(stderr,
"rank exceeds limit: %d\n", rank);
320 dinfo->
rank = tdim >= 0 ? rank -1 : rank;
322 for (i=0; i<dinfo->
rank; i++) {
324 if ( files[fid]->shared_mode ) {
327 size = (size_t)size_;
330 CHECK_ERROR( nc_inq_dim(ncid, dimids[rank-i-1], name, &size) )
332 fprintf(stderr,
"Length of the dimension name (%s) is too long (should be < %d).\n", name,
File_HSHORT);
341 if ( files[fid]->shared_mode ) {
350 strcat(name,
"_bnds");
356 buf = (
char*) malloc(l+1);
371 strcat(name,
"_bnds");
376 CHECK_ERROR( nc_inq_attlen (ncid, varid,
"units", &l) )
377 buf = (
char*) malloc(l+1);
378 CHECK_ERROR( nc_get_att_text(ncid, varid,
"units", buf) )
396 size_t *start, *count;
401 ncid = files[dinfo->
fid]->
ncid;
405 start = (
size_t*) malloc(
sizeof(
size_t)*rank);
406 count = (
size_t*) malloc(
sizeof(
size_t)*rank);
407 for (i=0; i<dinfo->
rank; i++) {
409 start[rank -i-1] = 0;
410 count[rank -i-1] = dinfo->
dim_size[i];
412 if (rank > dinfo->
rank) {
413 start[0] = dinfo->
step - 1;
416 switch ( precision ) {
418 status = nc_get_vara_double(ncid, varid, start, count, (
double*)var);
424 status = nc_get_vara_float(ncid, varid, start, count, (
float*)var);
432 fprintf(stderr,
"unsupported data precision: %d\n", precision );
446 int ncid, varid, rank;
449 ncid = files[dinfo->
fid]->
ncid;
453 if (rank > dinfo->
rank) {
454 start[0] = dinfo->
step - 1;
461 CHECK_PNC_ERROR( ncmpi_iget_vara(ncid, varid, start, count, var, ntypes, dtype, NULL) )
475 ncid = files[fid]->
ncid;
477 CHECK_ERROR( nc_inq_attlen(ncid, NC_GLOBAL, key, &l) )
480 CHECK_ERROR( nc_get_att_text(ncid, NC_GLOBAL, key, value) )
495 ncid = files[fid]->
ncid;
497 CHECK_ERROR( nc_inq_attlen(ncid, NC_GLOBAL, key, &l) )
499 CHECK_ERROR( nc_get_att_int(ncid, NC_GLOBAL, key, value) )
513 ncid = files[fid]->
ncid;
515 CHECK_ERROR( nc_inq_attlen(ncid, NC_GLOBAL, key, &l) )
517 CHECK_ERROR( nc_get_att_float(ncid, NC_GLOBAL, key, value) )
531 ncid = files[fid]->
ncid;
533 CHECK_ERROR( nc_inq_attlen(ncid, NC_GLOBAL, key, &l) )
535 CHECK_ERROR( nc_get_att_double(ncid, NC_GLOBAL, key, value) )
547 ncid = files[fid]->
ncid;
550 if (files[fid]->defmode == 0) {
552 files[fid]->defmode = 1;
556 if ( files[fid]->shared_mode ) {
557 CHECK_PNC_ERROR( ncmpi_put_att_text(ncid, NC_GLOBAL, key, strlen(value), value) )
560 CHECK_ERROR( nc_put_att_text(ncid, NC_GLOBAL, key, strlen(value), value) )
574 ncid = files[fid]->
ncid;
577 if (files[fid]->defmode == 0) {
579 files[fid]->defmode = 1;
583 if ( files[fid]->shared_mode ) {
584 CHECK_PNC_ERROR( ncmpi_put_att_int(ncid, NC_GLOBAL, key, NC_INT, len, value) )
587 CHECK_ERROR( nc_put_att_int(ncid, NC_GLOBAL, key, NC_INT, len, value) )
601 ncid = files[fid]->
ncid;
604 if (files[fid]->defmode == 0) {
606 files[fid]->defmode = 1;
610 if ( files[fid]->shared_mode ) {
611 CHECK_PNC_ERROR( ncmpi_put_att_float(ncid, NC_GLOBAL, key, NC_FLOAT, len, value) )
614 CHECK_ERROR( nc_put_att_float(ncid, NC_GLOBAL, key, NC_FLOAT, len, value) )
628 ncid = files[fid]->
ncid;
631 if (files[fid]->defmode == 0) {
633 files[fid]->defmode = 1;
637 if ( files[fid]->shared_mode ) {
638 CHECK_PNC_ERROR( ncmpi_put_att_double(ncid, NC_GLOBAL, key, NC_DOUBLE, len, value) )
641 CHECK_ERROR( nc_put_att_double(ncid, NC_GLOBAL, key, NC_DOUBLE, len, value) )
650 strcpy(files[fid]->time_units, time_units);
665 ncid = files[fid]->
ncid;
667 if ( files[fid]->shared_mode ) {
673 CHECK_PNC_ERROR( ncmpi_put_att_text(ncid, varid, key, strlen(val), val) )
678 if ( nc_inq_attid(ncid, varid, key, &attid) == NC_NOERR )
682 if (files[fid]->defmode == 0) {
684 files[fid]->defmode = 1;
688 CHECK_ERROR( nc_put_att_text(ncid, varid, key, strlen(val), val) )
704 int ncid, dimid, varid;
708 ncid = files[fid]->
ncid;
710 if ( nc_inq_varid(ncid, name, &varid) == NC_NOERR )
714 if (files[fid]->defmode == 0) {
716 files[fid]->defmode = 1;
720 if ( nc_inq_dimid(ncid, dim_name, &dimid) != NC_NOERR )
721 CHECK_ERROR( nc_def_dim(ncid, dim_name, size, &dimid) )
724 CHECK_ERROR( nc_def_var(ncid, name, xtype, 1, &dimid, &varid) )
725 CHECK_ERROR( nc_put_att_text(ncid, varid,
"long_name", strlen(desc), desc) )
726 CHECK_ERROR( nc_put_att_text(ncid, varid,
"units", strlen(units), units) )
730 files[fid]->defmode = 0;
733 switch ( precision ) {
735 CHECK_ERROR( nc_put_var_double(ncid, varid, (
double*)val) )
738 CHECK_ERROR( nc_put_var_float(ncid, varid, (
float*)val) )
741 fprintf(stderr,
"unsupported data precision: %d\n", precision);
756 int ncid, dimid, varid;
760 ncid = files[fid]->
ncid;
762 if ( files[fid]->shared_mode ) {
771 CHECK_PNC_ERROR( ncmpi_put_att_text(ncid, varid,
"long_name", strlen(desc), desc) )
772 CHECK_PNC_ERROR( ncmpi_put_att_text(ncid, varid,
"units", strlen(units), units) )
775 if ( nc_inq_varid(ncid, name, &varid) == NC_NOERR )
779 if (files[fid]->defmode == 0) {
781 files[fid]->defmode = 1;
785 if ( nc_inq_dimid(ncid, dim_name, &dimid) != NC_NOERR )
786 CHECK_ERROR( nc_def_dim(ncid, dim_name, dim_size, &dimid) )
789 CHECK_ERROR( nc_def_var(ncid, name, xtype, 1, &dimid, &varid) )
790 CHECK_ERROR( nc_put_att_text(ncid, varid,
"long_name", strlen(desc), desc) )
791 CHECK_ERROR( nc_put_att_text(ncid, varid,
"units", strlen(units), units) )
807 ncid = files[fid]->
ncid;
809 if ( files[fid]->shared_mode )
815 if ( (!files[fid]->shared_mode) && files[fid]->defmode == 1) {
817 files[fid]->defmode = 0;
821 switch ( precision ) {
823 if ( files[fid]->shared_mode )
824 CHECK_PNC_ERROR( ncmpi_iput_vara_double(ncid, varid, start, count, val, NULL) )
826 CHECK_ERROR( nc_put_var_double(ncid, varid, (
double*)val) )
829 if ( files[fid]->shared_mode )
830 CHECK_PNC_ERROR( ncmpi_iput_vara_float(ncid, varid, start, count, val, NULL) )
832 CHECK_ERROR( nc_put_var_float(ncid, varid, (
float*)val) )
835 fprintf(stderr,
"unsupported data precision: %d\n", precision);
852 int ncid, *dimids, varid;
857 ncid = files[fid]->
ncid;
859 if ( nc_inq_varid(ncid, name, &varid) == NC_NOERR )
863 if (files[fid]->defmode == 0) {
865 files[fid]->defmode = 1;
869 dimids = malloc(
sizeof(
int)*ndims);
870 for (i=0; i<ndims; i++)
871 CHECK_ERROR( nc_inq_dimid(ncid, dim_names[i], dimids+ndims-i-1) )
875 CHECK_ERROR( nc_def_var(ncid, name, xtype, ndims, dimids, &varid) )
876 CHECK_ERROR( nc_put_att_text(ncid, varid,
"long_name", strlen(desc), desc) )
877 CHECK_ERROR( nc_put_att_text(ncid, varid,
"units", strlen(units), units) )
882 files[fid]->defmode = 0;
885 switch ( precision ) {
887 CHECK_ERROR( nc_put_var_double(ncid, varid, (
double*)val) )
890 CHECK_ERROR( nc_put_var_float(ncid, varid, (
float*)val) )
893 fprintf(stderr,
"unsupported data precision: %d\n", precision);
908 int ncid, *dimids, varid;
913 ncid = files[fid]->
ncid;
915 if ( files[fid]->shared_mode ) {
919 dimids = malloc(
sizeof(
int)*ndims);
920 for (i=0; i<ndims; i++)
925 CHECK_PNC_ERROR( ncmpi_def_var(ncid, name, xtype, ndims, dimids, &varid) )
926 CHECK_PNC_ERROR( ncmpi_put_att_text(ncid, varid,
"long_name", strlen(desc), desc) )
927 CHECK_PNC_ERROR( ncmpi_put_att_text(ncid, varid,
"units", strlen(units), units) )
931 if ( nc_inq_varid(ncid, name, &varid) == NC_NOERR )
935 if (files[fid]->defmode == 0) {
937 files[fid]->defmode = 1;
941 dimids = malloc(
sizeof(
int)*ndims);
942 for (i=0; i<ndims; i++)
943 CHECK_ERROR( nc_inq_dimid(ncid, dim_names[i], dimids+ndims-i-1) )
947 CHECK_ERROR( nc_def_var(ncid, name, xtype, ndims, dimids, &varid) )
948 CHECK_ERROR( nc_put_att_text(ncid, varid,
"long_name", strlen(desc), desc) )
949 CHECK_ERROR( nc_put_att_text(ncid, varid,
"units", strlen(units), units) )
966 ncid = files[fid]->
ncid;
968 if ( files[fid]->shared_mode )
974 if ( (!files[fid]->shared_mode) && files[fid]->defmode == 1) {
976 files[fid]->defmode = 0;
980 switch ( precision ) {
982 if ( files[fid]->shared_mode )
983 CHECK_PNC_ERROR( ncmpi_iput_vara_double(ncid, varid, start, count, (
double*)val, NULL) )
985 CHECK_ERROR( nc_put_var_double(ncid, varid, (
double*)val) )
988 if ( files[fid]->shared_mode )
989 CHECK_PNC_ERROR( ncmpi_iput_vara_float(ncid, varid, start, count, (
float*)val, NULL) )
991 CHECK_ERROR( nc_put_var_float(ncid, varid, (
float*)val) )
994 fprintf(stderr,
"unsupported data precision: %d\n", precision);
1012 int ncid, varid, acid, *acdimids;
1013 int dimids[NC_MAX_DIMS], dimid;
1018 int i, j, k, n, m, err;
1027 fprintf(stderr,
"exceed max number of variable limit\n");
1032 ncid = files[fid]->
ncid;
1035 vars[nvar]->
ncid = ncid;
1036 vars[nvar]->
t = NULL;
1037 vars[nvar]->
start = NULL;
1038 vars[nvar]->
count = NULL;
1040 #if defined(NETCDF3) || defined(PNETCDF) 1041 if (files[fid]->defmode == 0) {
1042 if ( files[fid]->shared_mode )
1046 files[fid]->defmode = 1;
1052 for ( i=0; i<nt; i++ ) {
1053 if ( tdims[i] != NULL &&
1054 tdims[i]->ncid == ncid &&
1055 tdims[i]->tint == tint ) {
1056 vars[nvar]->
t = tdims[i];
1060 if ( vars[nvar]->t == NULL ) {
1062 tdims[nt]->
ncid = ncid;
1063 tdims[nt]->
count = -1;
1064 tdims[nt]->
tint = tint;
1065 tdims[nt]->
tval = (
double*) malloc(
sizeof(
double)*
NTMAX);
1068 strcpy(tname,
"time");
1070 sprintf(tname,
"time%d", nt);
1071 strcpy(tdims[nt]->name, tname);
1073 if ( files[fid]->shared_mode ) {
1075 tdims[nt]->
dimid = tdimid;
1076 CHECK_PNC_ERROR( ncmpi_def_var(ncid, tname, NC_DOUBLE, 1, &tdimid, &tvarid) )
1077 tdims[nt]->
varid = tvarid;
1078 strcpy(buf,
"time");
1079 CHECK_PNC_ERROR( ncmpi_put_att_text(ncid, tvarid,
"long_name", strlen(buf), buf) )
1080 CHECK_PNC_ERROR( ncmpi_put_att_text(ncid, tvarid,
"units", strlen(files[fid]->time_units), files[fid]->time_units) )
1084 sprintf(buf,
"%s_bnds", tname);
1085 CHECK_PNC_ERROR( ncmpi_put_att_text(ncid, tvarid,
"bounds", strlen(buf), buf) )
1087 CHECK_PNC_ERROR( ncmpi_def_var(ncid, buf, NC_DOUBLE, 2, dimids, &tvarid) )
1088 tdims[nt]->
bndsid = tvarid;
1089 CHECK_PNC_ERROR( ncmpi_put_att_text(ncid, tvarid,
"units", strlen(files[fid]->time_units), files[fid]->time_units) )
1092 CHECK_ERROR( nc_def_dim(ncid, tname, 0, &tdimid) )
1093 tdims[nt]->
dimid = tdimid;
1094 CHECK_ERROR( nc_def_var(ncid, tname, NC_DOUBLE, 1, &tdimid, &tvarid) )
1095 tdims[nt]->
varid = tvarid;
1096 strcpy(buf,
"time");
1097 CHECK_ERROR( nc_put_att_text(ncid, tvarid,
"long_name", strlen(buf), buf) )
1098 CHECK_ERROR( nc_put_att_text(ncid, tvarid,
"units", strlen(files[fid]->time_units), files[fid]->time_units) )
1100 if ( nc_inq_dimid(ncid,
"nv", &(dimids[1])) != NC_NOERR )
1101 CHECK_ERROR( nc_def_dim(ncid,
"nv", 2, &(dimids[1])) )
1102 sprintf(buf,
"%s_bnds", tname);
1103 CHECK_ERROR( nc_put_att_text(ncid, tvarid,
"bounds", strlen(buf), buf) )
1105 CHECK_ERROR( nc_def_var(ncid, buf, NC_DOUBLE, 2, dimids, &tvarid) )
1106 tdims[nt]->
bndsid = tvarid;
1107 CHECK_ERROR( nc_put_att_text(ncid, tvarid,
"units", strlen(files[fid]->time_units), files[fid]->time_units) )
1110 vars[nvar]->
t = tdims[nt];
1119 dimids[0] = vars[nvar]->
t->
dimid;
1122 for (i=ndims-n; i<ndims; i++) dimids[i] = -1;
1126 for (i=0; i<n; i++) {
1128 if ( files[fid]->shared_mode )
1131 err = nc_inq_dimid(ncid, dims[i], &dimid);
1132 if ( err == NC_NOERR ) {
1135 for (k=0; k<nndims; k++) {
1136 if (dimid == dimids[k]) {
1142 dimids[ndims-(++nndims)] = dimid;
1146 if ( files[fid]->shared_mode ) {
1149 acdimids = (
int*) malloc((
sizeof(
int)*m));
1155 acdimids = (
int*) malloc((
sizeof(
int)*m));
1156 CHECK_ERROR( nc_inq_vardimid(ncid, acid, acdimids) )
1158 for (j=m-1; j>=0; j--) {
1160 for (k=0; k<ndims; k++) {
1161 if (acdimids[j] == dimids[k]) {
1167 if ( nndims >= ndims ) {
1168 fprintf(stderr,
"Error: invalid associated coordinates\n");
1171 dimids[ndims-(++nndims)] = acdimids[j];
1181 fprintf(stderr,
"Error: invalid associated coordinates: %d %d\n", ndims, nndims);
1186 if ( files[fid]->shared_mode ) {
1187 CHECK_PNC_ERROR( ncmpi_def_var(ncid, varname, xtype, ndims, dimids, &varid) )
1189 CHECK_PNC_ERROR( ncmpi_put_att_text(ncid, varid,
"long_name", strlen(desc), desc) )
1190 CHECK_PNC_ERROR( ncmpi_put_att_text(ncid, varid,
"units", strlen(units), units) )
1195 CHECK_ERROR( nc_def_var(ncid, varname, xtype, ndims, dimids, &varid) )
1197 CHECK_ERROR( nc_put_att_text(ncid, varid,
"long_name", strlen(desc), desc) )
1198 CHECK_ERROR( nc_put_att_text(ncid, varid,
"units", strlen(units), units) )
1199 CHECK_ERROR( nc_put_att_double(ncid, varid, _FillValue, xtype, 1, &
rmiss) )
1200 CHECK_ERROR( nc_put_att_double(ncid, varid,
"missing_value", xtype, 1, &
rmiss) )
1203 strcpy(coord, dims[0]);
1204 for(i=1; i<n; i++) {
1205 if (strlen(coord)+strlen(dims[i])+1 <
File_HMID) {
1207 strcat(coord, dims[i]);
1210 if ( ndims > n && strlen(coord)+6 <
File_HMID) {
1212 strcat(coord, vars[nvar]->t->name);
1214 if ( files[fid]->shared_mode )
1215 CHECK_PNC_ERROR( ncmpi_put_att_text(ncid, varid,
"coordinates", strlen(coord), coord) )
1217 CHECK_ERROR( nc_put_att_text(ncid, varid,
"coordinates", strlen(coord), coord) )
1222 sprintf(buf,
"%s: mean", vars[nvar]->t->name);
1223 if ( files[fid]->shared_mode )
1224 CHECK_PNC_ERROR( ncmpi_put_att_text(ncid, varid,
"cell_methods", strlen(buf), buf) )
1226 CHECK_ERROR( nc_put_att_text(ncid, varid,
"cell_methods", strlen(buf), buf) )
1230 vars[nvar]->
start = (
size_t*) malloc(
sizeof(
size_t)*ndims);
1231 vars[nvar]->
count = (
size_t*) malloc(
sizeof(
size_t)*ndims);
1232 for ( i=0; i<ndims; i++ ) {
1233 if ( files[fid]->shared_mode ) {
1236 size = (size_t) dimlen;
1239 CHECK_ERROR( nc_inq_dimlen(ncid, dimids[i], &size) )
1240 vars[nvar]->
count[i] = size;
1241 vars[nvar]->
start[i] = 0;
1243 if ( tint > 0.0 ) vars[nvar]->
count[0] = 1;
1247 if ( ! files[fid]->shared_mode && files[fid]->deflate_level > 0 ) {
1248 CHECK_ERROR( nc_def_var_chunking(ncid, varid, NC_CHUNKED, vars[nvar]->count) )
1249 CHECK_ERROR( nc_def_var_deflate(ncid, varid, 0, 1, files[fid]->deflate_level) )
1253 vars[nvar]->
varid = varid;
1265 ncid = files[fid]->
ncid;
1267 #if defined(NETCDF3) || defined(PNETCDF) 1268 if (files[fid]->defmode == 1) {
1269 if ( files[fid]->shared_mode )
1273 files[fid]->defmode = 0;
1281 int32_t buf_amount )
1284 MPI_Offset buf_amount_ = buf_amount;
1287 ncid = files[fid]->
ncid;
1289 if ( files[fid]->shared_mode )
1300 ncid = files[fid]->
ncid;
1302 if ( files[fid]->shared_mode )
1313 ncid = files[fid]->
ncid;
1315 if ( files[fid]->shared_mode )
1334 ncid = vars[vid]->
ncid;
1337 if ( files[fid]->defmode == 1 && ! files[fid]->shared_mode ) {
1339 files[fid]->defmode = 0;
1343 varid = vars[vid]->
varid;
1344 if ( vars[vid]->t != NULL ) {
1345 if ( vars[vid]->t->count < 0 ||
1346 t_end > vars[vid]->
t->
t +
TEPS ) {
1347 vars[vid]->
t->
count += 1;
1348 vars[vid]->
t->
t = t_end;
1349 if ( vars[vid]->t->count >
NTMAX-1 ) {
1350 fprintf(stderr,
"time count exceeds the max limit (%d)\n",
NTMAX);
1354 if ( files[fid]->shared_mode ) {
1355 MPI_Offset index[2];
1356 index[0] = (MPI_Offset) vars[vid]->t->count;
1357 CHECK_PNC_ERROR( ncmpi_put_var1_double_all(ncid, vars[vid]->t->varid, index, &t_end) )
1359 CHECK_PNC_ERROR( ncmpi_put_var1_double_all(ncid, vars[vid]->t->bndsid, index, &t_start ) )
1361 CHECK_PNC_ERROR( ncmpi_put_var1_double_all(ncid, vars[vid]->t->bndsid, index, &t_end ) )
1364 index[0] = vars[vid]->
t->
count;
1365 CHECK_ERROR( nc_put_var1_double(ncid, vars[vid]->t->varid, index, &t_end) )
1367 CHECK_ERROR( nc_put_var1_double(ncid, vars[vid]->t->bndsid, index, &t_start) )
1369 CHECK_ERROR( nc_put_var1_double(ncid, vars[vid]->t->bndsid, index, &t_end) )
1373 size_t nt = vars[vid]->
t->
count + 1;
1376 for(n=nt-1;n>=0;n--) {
1377 if ( fabs(vars[vid]->t->tval[n]-t_end) <
TEPS ) {
1378 vars[vid]->
start[0] = n;
1384 fprintf(stderr,
"cannot find time: %f\n", t_end);
1385 fprintf(stderr,
" time count is : %d, last time is: %f, diff is: %e\n", vars[vid]->t->count < 0, vars[vid]->
t->
t, vars[vid]->
t->
t-t_end);
1386 fprintf(stderr,
" time is: ");
1387 for (n=0;n<nt;n++) fprintf(stderr,
"%f, ", vars[vid]->t->tval[n]);
1388 fprintf(stderr,
"\n");
1392 if ( files[fid]->shared_mode ) {
1396 for (i=ndims-1; i>0; i--) {
1397 start[i] = start[i-1];
1398 count[i] = count[i-1];
1400 start[0] = vars[vid]->
start[0];
1401 count[0] = vars[vid]->
count[0];
1405 switch (precision) {
1407 if ( files[fid]->shared_mode )
1408 CHECK_PNC_ERROR( ncmpi_bput_vara_double(ncid, varid, start, count, (
double*)var, NULL) )
1410 CHECK_ERROR( nc_put_vara_double(ncid, varid, vars[vid]->start, vars[vid]->count, (
double*)var) )
1413 if ( files[fid]->shared_mode )
1414 CHECK_PNC_ERROR( ncmpi_bput_vara_float(ncid, varid, start, count, (
float*)var, NULL) )
1416 CHECK_ERROR( nc_put_vara_float(ncid, varid, vars[vid]->start, vars[vid]->count, (
float*)var) )
1419 fprintf(stderr,
"unsupported data precision: %d\n", precision);
1432 ncid = files[fid]->
ncid;
1434 for (i=0; i<nvar; i++) {
1435 if ( vars[i] != NULL && vars[i]->ncid == ncid ) {
1436 free( vars[i]->start );
1437 free( vars[i]->count );
1443 for (i=0; i<nt; i++) {
1444 if ( tdims[i] != NULL && tdims[i]->ncid == ncid ) {
1445 free( tdims[i]->tval );
1451 if ( files[fid]->shared_mode )
int32_t dim_size[MAX_RANK]
char dim_name[File_HSHORT *MAX_RANK]
char description[File_HMID]
char time_units[File_HMID]
char varname[File_HSHORT]