int ex_put_info (int exoid, int num_info, char *info[]) { int status; int i, lindim, num_info_dim, dims[2], varid; size_t start[2], count[2]; char errmsg[MAX_ERR_LENGTH]; int rootid = exoid & EX_FILE_ID_MASK; exerrval = 0; /* clear error code */ /* only do this if there are records */ if (num_info > 0) { /* See if the number of info records has already been defined. Assume that if the DIM_NUM_INFO dimension exists, then the VAR_INFO variable also exists... */ status = nc_inq_dimid(rootid, DIM_NUM_INFO, &num_info_dim); if (status != NC_NOERR) { /* inquire previously defined dimensions */ if ((status = nc_inq_dimid(rootid, DIM_LIN, &lindim)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to get line string length in file id %d", rootid); ex_err("ex_put_info",errmsg,exerrval); return (EX_FATAL); } /* put file into define mode */ if ((status = nc_redef (rootid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed put file id %d into define mode", rootid); ex_err("ex_put_info",errmsg,exerrval); return (EX_FATAL); } /* define dimensions */ if ((status = nc_def_dim(rootid, DIM_NUM_INFO, num_info, &num_info_dim)) != NC_NOERR) { if (status == NC_ENAMEINUSE) { /* duplicate entry? */ exerrval = status; sprintf(errmsg, "Error: info records already exist in file id %d", rootid); ex_err("ex_put_info",errmsg,exerrval); } else { exerrval = status; sprintf(errmsg, "Error: failed to define number of info records in file id %d", rootid); ex_err("ex_put_info",errmsg,exerrval); } goto error_ret; /* exit define mode and return */ } /* define variable */ dims[0] = num_info_dim; dims[1] = lindim; if ((status = nc_def_var(rootid, VAR_INFO, NC_CHAR, 2, dims, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to define info record in file id %d", rootid); ex_err("ex_put_info",errmsg,exerrval); goto error_ret; /* exit define mode and return */ } ex_compress_variable(rootid, varid, 3); /* leave define mode */ if ((status = nc_enddef (rootid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to complete info record definition in file id %d", rootid); ex_err("ex_put_info",errmsg,exerrval); return (EX_FATAL); } } else { if ((status = nc_inq_varid(rootid, VAR_INFO, &varid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to find info record variable in file id %d", rootid); ex_err("ex_put_info",errmsg,exerrval); return (EX_FATAL); } } if (info != NULL) { /* write out information records */ for (i=0; i<num_info; i++) { int length = strlen(info[i]); start[0] = i; start[1] = 0; count[0] = 1; count[1] = length < MAX_LINE_LENGTH ? length : MAX_LINE_LENGTH; if ((status = nc_put_vara_text(rootid, varid, start, count, info[i])) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to store info record in file id %d", rootid); ex_err("ex_put_info",errmsg,exerrval); return (EX_FATAL); } } } else if (ex_is_parallel(rootid)) { /* All processors need to call nc_put_vara_text in case in a global collective mode */ char dummy[] = " "; for (i=0; i<num_info; i++) { start[0] = start[1] = 0; count[0] = count[1] = 0; nc_put_vara_text(rootid, varid, start, count, dummy); } } } return (EX_NOERR); /* Fatal error: exit definition mode and return */ error_ret: if (nc_enddef (rootid) != NC_NOERR) { /* exit define mode */ sprintf(errmsg, "Error: failed to complete definition for file id %d", rootid); ex_err("ex_put_info",errmsg,exerrval); } return (EX_FATAL); }
int ex_put_qa(int exoid, int num_qa_records, char *qa_record[][4]) { int status; int i, j, strdim, num_qa_dim, varid, n4dim; int dims[3]; size_t start[3], count[3]; char errmsg[MAX_ERR_LENGTH]; int rootid = exoid & EX_FILE_ID_MASK; ex_check_valid_file_id(exoid); exerrval = 0; /* clear error code */ /* only do this if there are records */ if (num_qa_records > 0) { /* See if the number of qa records has already been defined. Assume that if the DIM_NUM_QA dimension exists, then the VAR_QA_TITLE variable also exists... */ status = nc_inq_dimid(rootid, DIM_NUM_QA, &num_qa_dim); if (status != NC_NOERR) { /* inquire previously defined dimensions */ if ((status = nc_inq_dimid(rootid, DIM_STR, &strdim)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate string length in file id %d", rootid); ex_err("ex_put_qa", errmsg, exerrval); return (EX_FATAL); } if ((status = nc_inq_dimid(rootid, DIM_N4, &n4dim)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to locate record length in file id %d", rootid); ex_err("ex_put_qa", errmsg, exerrval); return (EX_FATAL); } /* put file into define mode */ if ((status = nc_redef(rootid)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to put file id %d into define mode", rootid); ex_err("ex_put_qa", errmsg, exerrval); return (EX_FATAL); } /* define dimensions */ if ((status = nc_def_dim(rootid, DIM_NUM_QA, num_qa_records, &num_qa_dim)) != NC_NOERR) { if (status == NC_ENAMEINUSE) { /* duplicate entry? */ exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: qa records already exist in file id %d", rootid); ex_err("ex_put_qa", errmsg, exerrval); } else { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to define qa record array size in file id %d", rootid); ex_err("ex_put_qa", errmsg, exerrval); } goto error_ret; /* exit define mode and return */ } /* define variable */ dims[0] = num_qa_dim; dims[1] = n4dim; dims[2] = strdim; if ((status = nc_def_var(rootid, VAR_QA_TITLE, NC_CHAR, 3, dims, &varid)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to define qa record array in file id %d", rootid); ex_err("ex_put_qa", errmsg, exerrval); goto error_ret; /* exit define mode and return */ } /* leave define mode */ if ((status = nc_enddef(rootid)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to complete definition in file id %d", rootid); ex_err("ex_put_qa", errmsg, exerrval); return (EX_FATAL); } } else { if ((status = nc_inq_varid(rootid, VAR_QA_TITLE, &varid)) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to find qa records variable in file id %d", rootid); ex_err("ex_put_qa", errmsg, exerrval); return (EX_FATAL); } } if (qa_record != NULL) { /* write out QA records */ for (i = 0; i < num_qa_records; i++) { for (j = 0; j < 4; j++) { start[0] = i; start[1] = j; start[2] = 0; count[0] = 1; count[1] = 1; count[2] = strlen(qa_record[i][j]) + 1; if ((status = nc_put_vara_text(rootid, varid, start, count, qa_record[i][j])) != NC_NOERR) { exerrval = status; snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to store qa record in file id %d", rootid); ex_err("ex_put_qa", errmsg, exerrval); return (EX_FATAL); } } } } else if (ex_is_parallel(rootid)) { /* In case we are in a collective mode, all processors need to call */ const char dummy[] = " "; for (i = 0; i < num_qa_records; i++) { for (j = 0; j < 4; j++) { start[0] = start[1] = start[2] = 0; count[0] = count[1] = count[2] = 0; nc_put_vara_text(rootid, varid, start, count, dummy); } } } } return (EX_NOERR); /* Fatal error: exit definition mode and return */ error_ret: if (nc_enddef(rootid) != NC_NOERR) { /* exit define mode */ snprintf(errmsg, MAX_ERR_LENGTH, "ERROR: failed to complete definition for file id %d", rootid); ex_err("ex_put_qa", errmsg, exerrval); } return (EX_FATAL); }
int ex_put_partial_set (int exoid, ex_entity_type set_type, ex_entity_id set_id, int64_t offset, int64_t num_to_put, const void_int *set_entry_list, const void_int *set_extra_list) { int dimid, status; int entry_list_id, extra_list_id, set_id_ndx; size_t start[1], count[1]; char errmsg[MAX_ERR_LENGTH]; char* entryptr = NULL; char* extraptr = NULL; exerrval = 0; /* clear error code */ /* first check if any sets are specified */ if ((status = nc_inq_dimid(exoid, ex_dim_num_objects(set_type), &dimid)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: no %ss defined in file id %d", ex_name_of_object(set_type), exoid); ex_err("ex_put_set",errmsg,exerrval); return (EX_FATAL); } /* Lookup index of set id in VAR_*S_IDS array */ set_id_ndx = ex_id_lkup(exoid, set_type,set_id); if (exerrval != 0) { if (exerrval == EX_NULLENTITY) { sprintf(errmsg, "Warning: no data allowed for NULL %s %"PRId64" in file id %d", ex_name_of_object(set_type),set_id,exoid); ex_err("ex_put_set",errmsg,EX_MSG); return (EX_WARN); } else { sprintf(errmsg, "Error: failed to locate %s id %"PRId64" in VAR_*S_IDS array in file id %d", ex_name_of_object(set_type), set_id,exoid); ex_err("ex_put_set",errmsg,exerrval); return (EX_FATAL); } } /* setup more pointers based on set_type */ if (set_type == EX_NODE_SET) { entryptr = VAR_NODE_NS(set_id_ndx); extraptr = NULL; } else if (set_type == EX_EDGE_SET) { entryptr = VAR_EDGE_ES(set_id_ndx); extraptr = VAR_ORNT_ES(set_id_ndx); } else if (set_type == EX_FACE_SET) { entryptr = VAR_FACE_FS(set_id_ndx); extraptr = VAR_ORNT_FS(set_id_ndx); } else if (set_type == EX_SIDE_SET) { entryptr = VAR_ELEM_SS(set_id_ndx); extraptr = VAR_SIDE_SS(set_id_ndx); } else if (set_type == EX_ELEM_SET) { entryptr = VAR_ELEM_ELS(set_id_ndx); extraptr = NULL; } /* inquire id's of previously defined variables */ if ((status = nc_inq_varid(exoid, entryptr, &entry_list_id)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to locate entry list for %s %"PRId64" in file id %d", ex_name_of_object(set_type), set_id,exoid); ex_err("ex_put_set",errmsg,exerrval); return (EX_FATAL); } /* only do for edge, face and side sets */ if (extraptr) { if ((status = nc_inq_varid(exoid, extraptr, &extra_list_id)) != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to locate extra list for %s %"PRId64" in file id %d", ex_name_of_object(set_type), set_id,exoid); ex_err("ex_put_set",errmsg,exerrval); return (EX_FATAL); } } /* write out the entry list and extra list arrays */ if (set_entry_list != NULL || ex_is_parallel(exoid)) { start[0] = offset-1; count[0] = num_to_put; if (count[0] == 0) start[0] = 0; if (ex_int64_status(exoid) & EX_BULK_INT64_API) { status = nc_put_vara_longlong(exoid, entry_list_id, start, count, set_entry_list); } else { status = nc_put_vara_int(exoid, entry_list_id, start, count, set_entry_list); } if (status != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to store entry list for %s %"PRId64" in file id %d", ex_name_of_object(set_type), set_id,exoid); ex_err("ex_put_set",errmsg,exerrval); return (EX_FATAL); } } /* only do for edge, face and side sets */ if (extraptr && set_extra_list != NULL ) { start[0] = offset-1; count[0] = num_to_put; if (ex_int64_status(exoid) & EX_BULK_INT64_API) { status = nc_put_vara_longlong(exoid, extra_list_id, start, count, set_extra_list); } else { status = nc_put_vara_int(exoid, extra_list_id, start, count, set_extra_list); } if (status != NC_NOERR) { exerrval = status; sprintf(errmsg, "Error: failed to store extra list for %s %"PRId64" in file id %d", ex_name_of_object(set_type), set_id,exoid); ex_err("ex_put_set",errmsg,exerrval); return (EX_FATAL); } } /* warn if extra data was sent in for node sets and elem sets */ if ((set_type == EX_NODE_SET || set_type == EX_ELEM_SET) && set_extra_list != NULL) { sprintf(errmsg, "Warning: extra list was ignored for %s %"PRId64" in file id %d", ex_name_of_object(set_type), set_id, exoid); ex_err("ex_put_set",errmsg,EX_MSG); return(EX_WARN); } return (EX_NOERR); }