static void get_reference (void) { int n, narrays, na, dim; cgsize_t vec[12]; CGNS_ENUMT(DataType_t) datatype; CGNS_ENUMT(AngleUnits_t) angle; int aloc = 0, units[5]; char name[33]; static char *refnames[4] = { "Mach", "AngleofAttack", "Reynolds", "TimeLatest" }; reference[0] = 0.5; /* Mach Number */ reference[1] = 0.0; /* angle of attack */ reference[2] = 1.0e6; /* Reynolds Number */ reference[3] = 0.0; /* time */ if (cg_goto (cgnsfn, cgnsbase, "ReferenceState_t", 1, "end") || cg_narrays (&narrays) || narrays < 1) return; for (na = 1; na <= narrays; na++) { if (cg_array_info (na, name, &datatype, &dim, vec)) FATAL ("get_reference", NULL); if (dim != 1 || vec[0] != 1) continue; for (n = 0; n < 4; n++) { if (!strcmp (refnames[n], name)) { if (cg_array_read_as (na, CGNS_ENUMV(RealDouble), &reference[n])) FATAL ("get_reference", NULL); if (n == 1) aloc = na; break; } } } /* angle of attack units */ if (aloc) { if (cg_goto (cgnsfn, cgnsbase, "ReferenceState_t", 1, "DataArray_t", aloc, "end")) FATAL ("get_reference", NULL); if (read_units (units)) angle = (CGNS_ENUMT(AngleUnits_t))units[4]; else angle = (CGNS_ENUMT(AngleUnits_t))baseunits[4]; if (angle == CGNS_ENUMV(Radian)) reference[1] *= 57.29578; } }
int main() { double data; int index_file,index_base,narrays,n,idim; char *state,arrayname[33]; DataClass_t id; DataType_t idata; cgsize_t idimvec; /* READ NONDIMENSIONAL INFO */ /* open CGNS file for read-only */ if (cg_open("grid_c.cgns",CG_MODE_READ,&index_file)) cg_error_exit(); /* we know there is only one base (real working code would check!) */ index_base=1; /* read DataClass under Base */ cg_goto(index_file,index_base,"end"); cg_dataclass_read(&id); printf("\nDataClass = %s\n",DataClassName[id]); if (id != NormalizedByUnknownDimensional) { printf("\nError! Expecting NormalizedByUnknownDimensional\n"); return 1; } /* read ReferenceState under Base */ cg_state_read(&state); printf("\nReferenceState = %s\n",state); /* Go to ReferenceState node, read Mach array and its dataclass */ cg_goto(index_file,index_base,"ReferenceState_t",1,"end"); /* find out how many data arrays */ cg_narrays(&narrays); for (n=1; n <= narrays; n++) { cg_array_info(n,arrayname,&idata,&idim,&idimvec); if (idim != 1 || idimvec != 1) { printf("\nError! expecting idim,idimvec=1,1\n"); printf(" they are idim,idimvec= %i, %i\n",idim,(int)idimvec); return 1; } cg_array_read_as(n,RealDouble,&data); printf("Variable=%s\n",arrayname); printf(" data=%18.8f\n",data); } /* close CGNS file */ cg_close(index_file); printf("\nSuccessfully read nondimensional info from file grid_c.cgns\n"); return 0; }
int main() { float cl[ntt]; int index_file,index_base,narrays,index_array,ndim; char arrayname[33]; DataType_t itype; cgsize_t idim; /* READ CONVERGENCE HISTORY INFORMATION FROM EXISTING CGNS FILE */ /* open CGNS file for read-only */ if (cg_open("grid_c.cgns",CG_MODE_READ,&index_file)) cg_error_exit(); /* we know there is only one base (real working code would check!) */ index_base=1; /* go to base node */ cg_goto(index_file,index_base,"end"); /* go to history node (we assume it exists and that there is only one - */ /* real working code would check!) */ cg_goto(index_file,index_base,"ConvergenceHistory_t",1,"end"); /* find out how many arrays are here (there should be only one!): */ cg_narrays(&narrays); index_array=narrays; /* some checks: */ if (narrays != 1) { printf("\nError! Expecting only one array, read %i\n",narrays); return 1; } cg_array_info(index_array,arrayname,&itype,&ndim,&idim); if (idim > ntt) { printf("\nError! must increase ntt to at least %i\n",(int)idim); return 1; } if (strcmp(arrayname,"CoefLift") != 0) { printf("\nError! expecting CoefLift, read %s\n",arrayname); return 1; } /* read lift coefficient array */ cg_array_read_as(index_array,RealSingle,cl); /* close CGNS file */ cg_close(index_file); printf("\nSuccessfully read cl history from file grid_c.cgns\n"); printf(" values are: %f, %f, %f, %f, %f\n",cl[0],cl[1],cl[2],cl[3],cl[4]); printf(" %f, %f, %f, %f, %f\n",cl[5],cl[6],cl[7],cl[8],cl[9]); return 0; }