00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026 #include <stdio.h>
00027 #include <stdlib.h>
00028 #include <string.h>
00029 #include <stdarg.h>
00030 #include <time.h>
00031 #include <sys/types.h>
00032 #include <sys/stat.h>
00033 #if defined(_WIN32) && !defined(__NUTC__)
00034 #include <io.h>
00035 #else
00036 #include <unistd.h>
00037 #endif
00038 #include "cgnslib.h"
00039 #include "cgns_header.h"
00040 #include "cgns_io.h"
00041 #if defined(_WIN32) && !defined(__NUTC__)
00042 #include <ctype.h>
00043 #ifndef F_OK
00044 #define R_OK 004
00045 #define W_OK 002
00046 #define X_OK 001
00047 #define F_OK 000
00048 #endif
00049
00050
00051 #ifdef NEED_FTOL2
00052 #ifdef __cplusplus
00053 extern "C" {
00054 #endif
00055 long _ftol(double);
00056 long _ftol2(double dValue) {return _ftol(dValue);}
00057 #ifdef __cplusplus
00058 }
00059 #endif
00060 #endif
00061 #endif
00062 #ifdef MEM_DEBUG
00063 #include "cg_malloc.h"
00064 #endif
00065
00066
00067
00068
00069 cgns_file *cgns_files = 0;
00070 cgns_file *cg;
00071 int n_cgns_files = 0;
00072 cgns_posit *posit = 0;
00073 int posit_file, posit_base, posit_zone;
00074 int CGNSLibVersion=CGNS_VERSION;
00075 int cgns_compress = -1;
00076 int cgns_filetype = CG_FILE_NONE;
00077
00078 extern void (*cgns_error_handler)(int, char *);
00079
00080
00081
00082
00083 char const * MassUnitsName[NofValidMassUnits] =
00084 {"Null", "UserDefined",
00085 "Kilogram", "Gram", "Slug", "PoundMass"
00086 };
00087 char const * LengthUnitsName[NofValidLengthUnits] =
00088 {"Null", "UserDefined",
00089 "Meter", "Centimeter", "Millimeter", "Foot", "Inch"
00090 };
00091 char const * TimeUnitsName[NofValidTimeUnits] =
00092 {"Null", "UserDefined",
00093 "Second"
00094 };
00095 char const * TemperatureUnitsName[NofValidTemperatureUnits] =
00096 {"Null", "UserDefined",
00097 "Kelvin", "Celsius", "Rankine", "Fahrenheit"
00098 };
00099 char const * AngleUnitsName[NofValidAngleUnits] =
00100 {"Null", "UserDefined",
00101 "Degree", "Radian"
00102 };
00103 char const * ElectricCurrentUnitsName[NofValidElectricCurrentUnits] =
00104 {"Null", "UserDefined",
00105 "Ampere", "Abampere", "Statampere", "Edison", "a.u."
00106 };
00107 char const * SubstanceAmountUnitsName[NofValidSubstanceAmountUnits] =
00108 {"Null", "UserDefined",
00109 "Mole", "Entities", "StandardCubicFoot", "StandardCubicMeter"
00110 };
00111 char const * LuminousIntensityUnitsName[NofValidLuminousIntensityUnits] =
00112 {"Null", "UserDefined",
00113 "Candela", "Candle", "Carcel", "Hefner", "Violle"
00114 };
00115 char const * DataClassName[NofValidDataClass] =
00116 {"Null", "UserDefined",
00117 "Dimensional", "NormalizedByDimensional",
00118 "NormalizedByUnknownDimensional", "NondimensionalParameter",
00119 "DimensionlessConstant"
00120 };
00121 char const * GridLocationName[NofValidGridLocation] =
00122 {"Null", "UserDefined",
00123 "Vertex", "CellCenter", "FaceCenter", "IFaceCenter",
00124 "JFaceCenter", "KFaceCenter", "EdgeCenter"
00125 };
00126 char const * BCDataTypeName[NofValidBCDataTypes] =
00127 {"Null", "UserDefined",
00128 "Dirichlet", "Neumann"
00129 };
00130 char const * GridConnectivityTypeName[NofValidGridConnectivityTypes] =
00131 {"Null", "UserDefined",
00132 "Overset", "Abutting", "Abutting1to1"
00133 };
00134 char const * PointSetTypeName[NofValidPointSetTypes] =
00135 {"Null", "UserDefined",
00136 "PointList", "PointListDonor",
00137 "PointRange", "PointRangeDonor",
00138 "ElementRange", "ElementList", "CellListDonor"
00139 };
00140 char const * GoverningEquationsTypeName[NofValidGoverningEquationsTypes]=
00141 {"Null", "UserDefined",
00142 "FullPotential", "Euler", "NSLaminar",
00143 "NSTurbulent", "NSLaminarIncompressible",
00144 "NSTurbulentIncompressible"
00145 };
00146 char const * ModelTypeName[NofValidModelTypes]=
00147 {"Null", "UserDefined",
00148 "Ideal", "VanderWaals", "Constant", "PowerLaw", "SutherlandLaw",
00149 "ConstantPrandtl", "EddyViscosity", "ReynoldsStress", "ReynoldsStressAlgebraic",
00150 "Algebraic_BaldwinLomax", "Algebraic_CebeciSmith",
00151 "HalfEquation_JohnsonKing", "OneEquation_BaldwinBarth",
00152 "OneEquation_SpalartAllmaras", "TwoEquation_JonesLaunder",
00153 "TwoEquation_MenterSST", "TwoEquation_Wilcox",
00154 "CaloricallyPerfect", "ThermallyPerfect",
00155 "ConstantDensity", "RedlichKwong",
00156 "Frozen", "ThermalEquilib", "ThermalNonequilib",
00157 "ChemicalEquilibCurveFit", "ChemicalEquilibMinimization",
00158 "ChemicalNonequilib",
00159 "EMElectricField", "EMMagneticField", "EMConductivity",
00160 "Voltage", "Interpolated", "Equilibrium_LinRessler", "Chemistry_LinRessler"
00161 };
00162 char const * BCTypeName[NofValidBCTypes] =
00163 {"Null", "UserDefined",
00164 "BCAxisymmetricWedge", "BCDegenerateLine", "BCDegeneratePoint",
00165 "BCDirichlet", "BCExtrapolate", "BCFarfield", "BCGeneral",
00166 "BCInflow", "BCInflowSubsonic", "BCInflowSupersonic", "BCNeumann",
00167 "BCOutflow", "BCOutflowSubsonic", "BCOutflowSupersonic",
00168 "BCSymmetryPlane", "BCSymmetryPolar", "BCTunnelInflow",
00169 "BCTunnelOutflow", "BCWall", "BCWallInviscid", "BCWallViscous",
00170 "BCWallViscousHeatFlux", "BCWallViscousIsothermal", "FamilySpecified"
00171 };
00172 char const * DataTypeName[NofValidDataTypes] =
00173 {"Null", "UserDefined",
00174 "Integer", "RealSingle", "RealDouble", "Character"
00175 };
00176 char const * ElementTypeName[NofValidElementTypes] =
00177 {"Null", "UserDefined",
00178 "NODE", "BAR_2", "BAR_3",
00179 "TRI_3", "TRI_6",
00180 "QUAD_4", "QUAD_8", "QUAD_9",
00181 "TETRA_4", "TETRA_10",
00182 "PYRA_5", "PYRA_13", "PYRA_14",
00183 "PENTA_6", "PENTA_15", "PENTA_18",
00184 "HEXA_8", "HEXA_20", "HEXA_27",
00185 "MIXED", "NGON_n", "NFACE_n"
00186 };
00187 char const * ZoneTypeName[NofValidZoneTypes] =
00188 {"Null", "UserDefined",
00189 "Structured", "Unstructured"
00190 };
00191 char const * RigidGridMotionTypeName[NofValidRigidGridMotionTypes] =
00192 {"Null", "UserDefined",
00193 "ConstantRate", "VariableRate"
00194 };
00195 char const * ArbitraryGridMotionTypeName[NofValidArbitraryGridMotionTypes] =
00196 {"Null", "UserDefined",
00197 "NonDeformingGrid", "DeformingGrid"
00198 };
00199 char const * SimulationTypeName[NofValidSimulationTypes] =
00200 {"Null", "UserDefined",
00201 "TimeAccurate", "NonTimeAccurate"
00202 };
00203 char const * WallFunctionTypeName[NofValidWallFunctionTypes] =
00204 {"Null", "UserDefined", "Generic"
00205 };
00206 char const * AreaTypeName[NofValidAreaTypes] =
00207 {"Null", "UserDefined",
00208 "BleedArea", "CaptureArea"
00209 };
00210 char const * AverageInterfaceTypeName[NofValidAverageInterfaceTypes] =
00211 {"Null", "UserDefined",
00212 "AverageAll", "AverageCircumferential", "AverageRadial",
00213 "AverageI", "AverageJ", "AverageK"
00214 };
00215
00216
00217
00218
00219 int n_open = 0;
00220 int cgns_file_size = 0;
00221 int file_number_offset = 0;
00222 int VersionList[] = {3000, 2530, 2520, 2510, 2500, 2460, 2420, 2400,
00223 2300, 2200, 2100, 2000, 1270, 1200, 1100, 1050};
00224 #define nVersions (sizeof(VersionList)/sizeof(int))
00225
00226
00227
00228
00229
00230
00231
00232 int cg_is_cgns(const char *filename, int *file_type) {
00233 int cgio, ierr;
00234 double rootid, childid;
00235
00236 *file_type = CG_FILE_NONE;
00237 if (cgio_open_file(filename, CG_MODE_READ, CG_FILE_NONE, &cgio))
00238 return CG_ERROR;
00239 cgio_get_root_id(cgio, &rootid);
00240 cgio_get_file_type(cgio, file_type);
00241 ierr = cgio_get_node_id(cgio, rootid, "CGNSLibraryVersion", &childid);
00242 cgio_close_file(cgio);
00243 return ierr ? CG_ERROR : CG_OK;
00244 }
00245
00246
00247
00248
00249
00250
00251 int cg_open(char const * filename, int mode, int *file_number) {
00252 int not_found, dim_vals, cgio;
00253 double dummy_id;
00254 float FileVersion;
00255
00256
00257
00258
00259 not_found = access(filename, F_OK) ;
00260
00261
00262 switch(mode) {
00263 case CG_MODE_READ:
00264 if (not_found) {
00265 cgi_error("Error opening file: '%s' not found!", filename);
00266 return CG_ERROR;
00267 }
00268 break;
00269 case CG_MODE_WRITE:
00270 if (!not_found) {
00271 unlink(filename);
00272
00273
00274
00275 }
00276 break;
00277 case CG_MODE_MODIFY:
00278 if (not_found) {
00279 cgi_error("Error opening file: '%s' not found!", filename);
00280 return CG_ERROR;
00281 }
00282 break;
00283 default:
00284 cgi_error("Unknown opening file mode: %d ??",mode);
00285 return CG_ERROR;
00286 }
00287
00288
00289 if (cgns_filetype == CG_FILE_NONE)
00290 cg_set_file_type(CG_FILE_NONE);
00291
00292
00293 if (cgio_open_file(filename, mode, cgns_filetype, &cgio)) {
00294 cg_io_error("cgio_open_file");
00295 return CG_ERROR;
00296 }
00297 n_open++;
00298
00299
00300 if (cgns_file_size == 0) {
00301 cgns_file_size = 1;
00302 cgns_files = CGNS_NEW(cgns_file,cgns_file_size);
00303 } else if (n_cgns_files == cgns_file_size) {
00304 cgns_file_size *= 2;
00305 cgns_files = CGNS_RENEW(cgns_file,cgns_file_size, cgns_files);
00306 }
00307 cg = &(cgns_files[n_cgns_files]);
00308 n_cgns_files++;
00309 (*file_number) = n_cgns_files + file_number_offset;
00310
00311
00312 cg->mode = mode;
00313 cg->filename = CGNS_NEW(char,strlen(filename) + 1);
00314 strcpy(cg->filename, filename);
00315 cg->cgio = cgio;
00316 cgio_get_root_id(cgio, &cg->rootid);
00317 cg->file_number = (*file_number);
00318 cg->version = 0;
00319 cg->deleted = 0;
00320 cg->added = 0;
00321
00322
00323 if (mode == CG_MODE_WRITE) {
00324 dim_vals = 1;
00325 FileVersion = (float) CGNS_DOTVERS;
00326 if (cgi_new_node(cg->rootid, "CGNSLibraryVersion",
00327 "CGNSLibraryVersion_t", &dummy_id, "R4", 1, &dim_vals,
00328 (void *)&FileVersion)) return CG_ERROR;
00329 cg->version = CGNSLibVersion;
00330 }
00331 else {
00332
00333
00334 if (cg_version(cg->file_number, &FileVersion)) return CG_ERROR;
00335
00336
00337
00338
00339 if (cg->version > CGNSLibVersion) {
00340
00341
00342
00343 if ((cg->version / 1000) > (CGNSLibVersion / 1000)) {
00344 cgi_error("The file %s was written with a more recent version of the CGNS library. You must update your CGNS library before trying to read this file.",filename);
00345 return CG_ERROR;
00346 }
00347
00348 if ((cg->version / 100) > (CGNSLibVersion / 100)) {
00349 cgi_warning("The file being read is more recent that the CGNS library used");
00350 }
00351 }
00352 }
00353
00354
00355
00356 if (cgio_file_version(cg->cgio, cg->dtb_version, cg->creation_date,
00357 cg->modify_date)) {
00358 cg_io_error("cgio_file_version");
00359 return CG_ERROR;
00360 }
00361 if (cgio_library_version(cg->cgio, cg->adf_lib_version)) {
00362 cg_io_error("cgio_library_version");
00363 return CG_ERROR;
00364 }
00365
00366
00367 if (mode == CG_MODE_READ || mode == CG_MODE_MODIFY) {
00368 if (cgi_read()) return CG_ERROR;
00369
00370
00371 if (cg->version < CGNSLibVersion && mode == CG_MODE_MODIFY) {
00372 int nnod;
00373 double *id;
00374 FileVersion = (float)CGNS_DOTVERS;
00375 if (cgi_get_nodes(cg->rootid, "CGNSLibraryVersion_t",
00376 &nnod, &id))
00377 return CG_ERROR;
00378 if (nnod) {
00379 if (cgio_write_all_data(cg->cgio, id[0], &FileVersion)) {
00380 cg_io_error("cgio_write_all_data");
00381 return CG_ERROR;
00382 }
00383 free(id);
00384 }
00385 else {
00386 dim_vals = 1;
00387 if (cgi_new_node(cg->rootid, "CGNSLibraryVersion",
00388 "CGNSLibraryVersion_t", &dummy_id, "R4", 1, &dim_vals,
00389 (void *)&FileVersion)) return CG_ERROR;
00390 }
00391 cg->version = CGNSLibVersion;
00392 }
00393 } else {
00394 cg->nbases=0;
00395 cg->base = 0;
00396 }
00397
00398 return CG_OK;
00399 }
00400
00401 int cg_version(int file_number, float *FileVersion) {
00402 int nnod;
00403 double *id;
00404
00405 cg = cgi_get_file(file_number);
00406 if (cg == 0) return CG_ERROR;
00407
00408
00409 if (cg->version) {
00410 (*FileVersion)=(float)(cg->version)/1000;
00411 return CG_OK;
00412 }
00413
00414
00415
00416 if (cgi_get_nodes(cg->rootid, "CGNSLibraryVersion_t", &nnod, &id))
00417 return CG_ERROR;
00418 if (nnod==0) {
00419 cg->version=1050;
00420 *FileVersion= (float) 1.05;
00421 } else if (nnod!=1) {
00422 cgi_error("More then one CGNSLibraryVersion_t node found under ROOT.");
00423 return CG_ERROR;
00424 } else {
00425 int vers, ndim, dim_vals[12], temp_version;
00426 char_33 node_name;
00427 char_33 data_type;
00428 void *data;
00429
00430 if (cgi_read_node(id[0], node_name, data_type, &ndim, dim_vals,
00431 &data, 1)) {
00432 cgi_error("Error reading CGNS-Library-Version");
00433 return CG_ERROR;
00434 }
00435
00436 if (strcmp(data_type,"R4")!=0) {
00437 cgi_error("Unexpected data type for CGNS-Library-Version='%s'",data_type);
00438 return CG_ERROR;
00439 }
00440
00441 if (ndim != 1 || (dim_vals[0]!=1)) {
00442 cgi_error("Wrong data dimension for CGNS-Library-Version");
00443 return CG_ERROR;
00444 }
00445
00446 *FileVersion = *((float *)data);
00447 free(data);
00448 cg->version = (int)(1000.0*(*FileVersion)+0.5);
00449
00450
00451 temp_version = cg->version;
00452
00453 for (vers=0; vers<nVersions; vers++) {
00454 if (temp_version > (VersionList[vers]-2) &&
00455 temp_version < (VersionList[vers]+2)) {
00456 cg->version = VersionList[vers];
00457 break;
00458 }
00459 }
00460 if (cg->version == 0) {
00461 cgi_error("Error: Unable to determine the version number");
00462 return CG_ERROR;
00463 }
00464
00465 free(id);
00466 }
00467 #if DEBUG_VERSION
00468 printf("FileVersion=%f\n",*FileVersion);
00469 printf("cg->version=%d\n",cg->version);
00470 #endif
00471
00472 return CG_OK;
00473 }
00474
00475 int cg_close(int file_number) {
00476
00477 cg = cgi_get_file(file_number);
00478 if (cg == 0) return CG_ERROR;
00479
00480 if (cgns_compress && cg->mode == CG_MODE_MODIFY &&
00481 (cg->deleted || cgns_compress == 1)) {
00482 if (cgio_compress_file (cg->cgio, cg->filename)) {
00483 cg_io_error("cgio_compress_file");
00484 return CG_ERROR;
00485 }
00486 }
00487 else {
00488 if (cgio_close_file(cg->cgio)) {
00489 cg_io_error("cgio_close_file");
00490 return CG_ERROR;
00491 }
00492 }
00493 n_open--;
00494
00495
00496 cgi_free_file(cg);
00497 cg->mode = CG_MODE_CLOSED;
00498
00499
00500
00501 if (n_open == 0) {
00502 file_number_offset = n_cgns_files;
00503 free (cgns_files);
00504 cgns_files = 0;
00505 cgns_file_size = 0;
00506 n_cgns_files = 0;
00507 }
00508
00509 return CG_OK;
00510 }
00511
00512 int cg_save_as(int file_number, const char *filename, int file_type,
00513 int follow_links)
00514 {
00515 int output;
00516
00517 cg = cgi_get_file(file_number);
00518 if (cg == 0) return CG_ERROR;
00519
00520 if (file_type == CG_FILE_NONE)
00521 file_type = cgns_filetype;
00522 if (cgio_is_supported(file_type)) {
00523 cgi_error("file type unknown or not supported");
00524 return CG_ERROR;
00525 }
00526 if (cgio_open_file(filename, CG_MODE_WRITE, file_type, &output)) {
00527 cg_io_error ("cgio_open_file");
00528 return CG_ERROR;
00529 }
00530 if (cgio_copy_file(cg->cgio, output, follow_links)) {
00531 cg_io_error("cgio_copy_file");
00532 return CG_ERROR;
00533 }
00534 if (cgio_close_file(output)) {
00535 cg_io_error("cgio_close_file");
00536 return CG_ERROR;
00537 }
00538 return CG_OK;
00539 }
00540
00541 int cg_set_file_type(int file_type) {
00542 if (file_type == CG_FILE_NONE) {
00543 char *type = getenv("CGNS_FILETYPE");
00544 if (type == NULL || !*type)
00545 cgns_filetype = CG_FILE_ADF;
00546 #ifdef BUILD_HDF5
00547 else if (*type == '2' || *type == 'h' || *type == 'H')
00548 cgns_filetype = CG_FILE_HDF5;
00549 #endif
00550 #ifdef BUILD_XML
00551 else if (*type == '3' || *type == 'x' || *type == 'X')
00552 cgns_filetype = CG_FILE_XML;
00553 #endif
00554 else
00555 cgns_filetype = CG_FILE_ADF;
00556 }
00557 else {
00558 if (cgio_is_supported(file_type)) {
00559 cgi_error("file type unknown or not supported");
00560 return CG_ERROR;
00561 }
00562 cgns_filetype = file_type;
00563 }
00564 return CG_OK;
00565 }
00566
00567 int cg_get_file_type(int file_number, int *file_type) {
00568 cg = cgi_get_file(file_number);
00569 if (cg == 0) return CG_ERROR;
00570 if (cgio_get_file_type(cg->cgio, file_type)) {
00571 cg_io_error("cgio_get_file_type");
00572 return CG_ERROR;
00573 }
00574 return CG_OK;
00575 }
00576
00577 int cg_root_id(int file_number, double *root_id) {
00578 cg = cgi_get_file(file_number);
00579 if (cg == 0) return CG_ERROR;
00580 if (cgio_get_root_id(cg->cgio, root_id)) {
00581 cg_io_error("cgio_get_root_id");
00582 return CG_ERROR;
00583 }
00584 return CG_OK;
00585 }
00586
00587
00588
00589 int cg_configure(int what, void *value) {
00590
00591 if (what > 100) {
00592 if (cgio_configure(what, value)) {
00593 cg_io_error("cgio_configure");
00594 return CG_ERROR;
00595 }
00596 }
00597
00598 else if (what == CG_CONFIG_ERROR) {
00599 cgns_error_handler = (void (*)(int, char *))value;
00600 }
00601
00602 else if (what == CG_CONFIG_COMPRESS) {
00603 cgns_compress = (int)((size_t)value);
00604 }
00605
00606 else if (what == CG_CONFIG_SET_PATH) {
00607 return cg_set_path((const char *)value);
00608 }
00609
00610 else if (what == CG_CONFIG_ADD_PATH) {
00611 return cg_set_path((const char *)value);
00612 }
00613
00614 else if (what == CG_CONFIG_FILE_TYPE) {
00615 return cg_set_file_type((int)((size_t)value));
00616 }
00617 else {
00618 cgi_error("unknown config setting");
00619 return CG_ERROR;
00620 }
00621 return CG_OK;
00622 }
00623
00624 int cg_error_handler(void (*func)(int, char *)) {
00625 cgns_error_handler = func;
00626 return CG_OK;
00627 }
00628
00629 int cg_set_compress(int compress) {
00630 cgns_compress = compress;
00631 return CG_OK;
00632 }
00633
00634 int cg_get_compress(int *compress) {
00635 *compress = cgns_compress;
00636 return CG_OK;
00637 }
00638
00639 int cg_set_path(const char *path) {
00640 cgio_path_delete(NULL);
00641 if (path && *path) {
00642 if (cgio_path_add(path)) {
00643 cg_io_error("cgio_path_add");
00644 return CG_ERROR;
00645 }
00646 }
00647 return CG_OK;
00648 }
00649
00650 int cg_add_path(const char *path) {
00651 if (cgio_path_add(path)) {
00652 cg_io_error("cgio_path_add");
00653 return CG_ERROR;
00654 }
00655 return CG_OK;
00656 }
00657
00658
00659
00660
00661
00662
00663
00664 const char *cg_get_name(int nnames, const char **names, int type) {
00665 if (type < 0 || type >= nnames) return "<invalid>";
00666 return names[type];
00667 }
00668
00669 const char *cg_MassUnitsName(MassUnits_t type) {
00670 return cg_get_name(NofValidMassUnits,MassUnitsName,(int)type);
00671 }
00672 const char *cg_LengthUnitsName(LengthUnits_t type) {
00673 return cg_get_name(NofValidLengthUnits,LengthUnitsName,(int)type);
00674 }
00675 const char *cg_TimeUnitsName(TimeUnits_t type) {
00676 return cg_get_name(NofValidTimeUnits,TimeUnitsName,(int)type);
00677 }
00678 const char *cg_TemperatureUnitsName(TemperatureUnits_t type) {
00679 return cg_get_name(NofValidTemperatureUnits,TemperatureUnitsName,(int)type);
00680 }
00681 const char *cg_AngleUnitsName(AngleUnits_t type) {
00682 return cg_get_name(NofValidAngleUnits,AngleUnitsName,(int)type);
00683 }
00684 const char *cg_ElectricCurrentUnitsName(ElectricCurrentUnits_t type) {
00685 return cg_get_name(NofValidElectricCurrentUnits,ElectricCurrentUnitsName,(int)type);
00686 }
00687 const char *cg_SubstanceAmountUnitsName(SubstanceAmountUnits_t type) {
00688 return cg_get_name(NofValidSubstanceAmountUnits,SubstanceAmountUnitsName,(int)type);
00689 }
00690 const char *cg_LuminousIntensityUnitsName(LuminousIntensityUnits_t type) {
00691 return cg_get_name(NofValidLuminousIntensityUnits,LuminousIntensityUnitsName,(int)type);
00692 }
00693 const char *cg_DataClassName(DataClass_t type) {
00694 return cg_get_name(NofValidDataClass,DataClassName,(int)type);
00695 }
00696 const char *cg_GridLocationName(GridLocation_t type) {
00697 return cg_get_name(NofValidGridLocation,GridLocationName,(int)type);
00698 }
00699 const char *cg_BCDataTypeName(BCDataType_t type) {
00700 return cg_get_name(NofValidBCDataTypes,BCDataTypeName,(int)type);
00701 }
00702 const char *cg_GridConnectivityTypeName(GridConnectivityType_t type) {
00703 return cg_get_name(NofValidGridConnectivityTypes,GridConnectivityTypeName,(int)type);
00704 }
00705 const char *cg_PointSetTypeName(PointSetType_t type) {
00706 return cg_get_name(NofValidPointSetTypes,PointSetTypeName,(int)type);
00707 }
00708 const char *cg_GoverningEquationsTypeName(GoverningEquationsType_t type) {
00709 return cg_get_name(NofValidGoverningEquationsTypes,GoverningEquationsTypeName,(int)type);
00710 }
00711 const char *cg_ModelTypeName(ModelType_t type) {
00712 return cg_get_name(NofValidModelTypes,ModelTypeName,(int)type);
00713 }
00714 const char *cg_BCTypeName(BCType_t type) {
00715 return cg_get_name(NofValidBCTypes,BCTypeName,(int)type);
00716 }
00717 const char *cg_DataTypeName(DataType_t type) {
00718 return cg_get_name(NofValidDataTypes,DataTypeName,(int)type);
00719 }
00720 const char *cg_ElementTypeName(ElementType_t type) {
00721 return cg_get_name(NofValidElementTypes,ElementTypeName,(int)type);
00722 }
00723 const char *cg_ZoneTypeName(ZoneType_t type) {
00724 return cg_get_name(NofValidZoneTypes,ZoneTypeName,(int)type);
00725 }
00726 const char *cg_RigidGridMotionTypeName(RigidGridMotionType_t type) {
00727 return cg_get_name(NofValidRigidGridMotionTypes,RigidGridMotionTypeName,(int)type);
00728 }
00729 const char *cg_ArbitraryGridMotionTypeName(ArbitraryGridMotionType_t type) {
00730 return cg_get_name(NofValidArbitraryGridMotionTypes,ArbitraryGridMotionTypeName,(int)type);
00731 }
00732 const char *cg_SimulationTypeName(SimulationType_t type) {
00733 return cg_get_name(NofValidSimulationTypes,SimulationTypeName,(int)type);
00734 }
00735 const char *cg_WallFunctionTypeName(WallFunctionType_t type) {
00736 return cg_get_name(NofValidWallFunctionTypes,WallFunctionTypeName,(int)type);
00737 }
00738 const char *cg_AreaTypeName(AreaType_t type) {
00739 return cg_get_name(NofValidAreaTypes,AreaTypeName,(int)type);
00740 }
00741 const char *cg_AverageInterfaceTypeName(AverageInterfaceType_t type) {
00742 return cg_get_name(NofValidAverageInterfaceTypes,AverageInterfaceTypeName,(int)type);
00743 }
00744
00745
00746
00747
00748
00749 int cg_nbases(int file_number, int *nbases) {
00750
00751 cg = cgi_get_file(file_number);
00752 if (cg == 0) return CG_ERROR;
00753
00754 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
00755
00756 *nbases = cg->nbases;
00757 return CG_OK;
00758 }
00759
00760 int cg_base_read(int file_number, int B, char *basename, int *cell_dim,
00761 int *phys_dim) {
00762 cgns_base *base;
00763
00764 cg = cgi_get_file(file_number);
00765 if (cg == 0) return CG_ERROR;
00766
00767 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
00768
00769 base = cgi_get_base(cg, B);
00770 if (base==0) return CG_ERROR;
00771
00772 *cell_dim = base->cell_dim;
00773 *phys_dim = base->phys_dim;
00774 strcpy(basename, base->name);
00775
00776 return CG_OK;
00777 }
00778
00779 int cg_base_id(int file_number, int B, double *base_id) {
00780 cgns_base *base;
00781
00782 cg = cgi_get_file(file_number);
00783 if (cg == 0) return CG_ERROR;
00784
00785 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
00786
00787 base = cgi_get_base(cg, B);
00788 if (base==0) return CG_ERROR;
00789
00790 *base_id = base->id;
00791 return CG_OK;
00792 }
00793
00794
00795
00796
00797 int cg_nzones(int file_number, int B, int *nzones) {
00798 cgns_base *base;
00799
00800 cg = cgi_get_file(file_number);
00801 if (cg == 0) return CG_ERROR;
00802
00803 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
00804
00805 base = cgi_get_base(cg, B);
00806 if (base==0) return CG_ERROR;
00807
00808 *nzones = base->nzones;
00809 return CG_OK;
00810 }
00811
00812 int cg_zone_type(int file_number, int B, int Z, ZoneType_t *type) {
00813 cgns_zone *zone;
00814
00815 cg = cgi_get_file(file_number);
00816 if (cg == 0) return CG_ERROR;
00817
00818 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
00819
00820 zone = cgi_get_zone(cg, B, Z);
00821 if (zone==0) return CG_ERROR;
00822
00823 *type = zone->type;
00824 return CG_OK;
00825 }
00826
00827 int cg_zone_read(int file_number, int B, int Z, char *zonename,
00828 int *nijk) {
00829 cgns_zone *zone;
00830 int i;
00831
00832 cg = cgi_get_file(file_number);
00833 if (cg == 0) return CG_ERROR;
00834
00835 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
00836
00837 zone = cgi_get_zone(cg, B, Z);
00838 if (zone==0) return CG_ERROR;
00839
00840 strcpy(zonename, zone->name);
00841
00842 for (i=0; i<3*(zone->index_dim); i++) nijk[i] = zone->nijk[i];
00843
00844 return CG_OK;
00845 }
00846
00847 int cg_zone_id(int file_number, int B, int Z, double *zone_id) {
00848 cgns_zone *zone;
00849
00850 cg = cgi_get_file(file_number);
00851 if (cg == 0) return CG_ERROR;
00852
00853 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
00854
00855 zone = cgi_get_zone(cg, B, Z);
00856 if (zone==0) return CG_ERROR;
00857
00858 *zone_id = zone->id;
00859 return CG_OK;
00860 }
00861
00862
00863
00864
00865 int cg_nfamilies(int file_number, int B, int *nfamilies) {
00866 cgns_base *base;
00867
00868 cg = cgi_get_file(file_number);
00869 if (cg == 0) return CG_ERROR;
00870
00871 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
00872
00873 base = cgi_get_base(cg, B);
00874 if (base==0) return CG_ERROR;
00875
00876 *nfamilies = base->nfamilies;
00877 return CG_OK;
00878 }
00879
00880 int cg_family_read(int file_number, int B, int F, char *family_name,
00881 int *nboco, int *ngeos) {
00882
00883 cgns_family *family;
00884
00885 cg = cgi_get_file(file_number);
00886 if (cg == 0) return CG_ERROR;
00887
00888 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
00889
00890 family = cgi_get_family(cg, B, F);
00891 if (family==0) return CG_ERROR;
00892
00893 strcpy(family_name, family->name);
00894 *nboco = family->nfambc;
00895 *ngeos = family->ngeos;
00896
00897 return CG_OK;
00898 }
00899
00900 int cg_fambc_read(int file_number, int B, int F, int BC,
00901 char *fambc_name, BCType_t *bocotype) {
00902 cgns_family *family;
00903
00904 cg = cgi_get_file(file_number);
00905 if (cg == 0) return CG_ERROR;
00906
00907 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
00908
00909 family = cgi_get_family(cg, B, F);
00910 if (family==0) return CG_ERROR;
00911
00912 if (BC<=0 || BC>family->nfambc) {
00913 cgi_error("Invalid family b.c. number");
00914 return CG_ERROR;
00915 }
00916 strcpy(fambc_name,family->fambc[BC-1].name);
00917 *bocotype = family->fambc[BC-1].type;
00918
00919 return CG_OK;
00920 }
00921
00922 int cg_geo_read(int file_number, int B, int F, int G, char *geo_name,
00923 char **geo_file, char *CAD_name, int *npart) {
00924 cgns_family *family;
00925
00926 cg = cgi_get_file(file_number);
00927 if (cg == 0) return CG_ERROR;
00928
00929 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
00930
00931 family = cgi_get_family(cg, B, F);
00932 if (family==0) return CG_ERROR;
00933
00934 if (G<=0 || G>family->ngeos) {
00935 cgi_error("Invalid geometry reference number");
00936 return CG_ERROR;
00937 }
00938 strcpy(geo_name,family->geo[G-1].name);
00939 strcpy(CAD_name,family->geo[G-1].format);
00940
00941
00942
00943 geo_file[0]=CGNS_NEW(char,strlen(family->geo[G-1].file)+1);
00944 strcpy(geo_file[0],family->geo[G-1].file);
00945
00946 *npart=family->geo[G-1].npart;
00947
00948 return CG_OK;
00949 }
00950
00951 int cg_part_read(int file_number, int B, int F, int G, int P, char *part_name) {
00952 cgns_family *family;
00953
00954 cg = cgi_get_file(file_number);
00955 if (cg == 0) return CG_ERROR;
00956
00957 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
00958
00959 family = cgi_get_family(cg, B, F);
00960 if (family==0) return CG_ERROR;
00961
00962 if (P<=0 || P>family->geo[G-1].npart) {
00963 cgi_error("Invalid part number");
00964 return CG_ERROR;
00965 }
00966 strcpy(part_name,family->geo[G-1].part[P-1].name);
00967 return CG_OK;
00968 }
00969
00970
00971
00972
00973 int cg_ndiscrete(int file_number, int B, int Z, int *ndiscrete) {
00974 cgns_zone *zone;
00975
00976 cg = cgi_get_file(file_number);
00977 if (cg == 0) return CG_ERROR;
00978
00979 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
00980
00981 zone = cgi_get_zone(cg, B, Z);
00982 if (zone==0) return CG_ERROR;
00983
00984 (*ndiscrete) = zone->ndiscrete;
00985 return CG_OK;
00986 }
00987
00988 int cg_discrete_read(int file_number, int B, int Z, int D, char *discrete_name) {
00989
00990 cgns_discrete *discrete;
00991
00992 cg = cgi_get_file(file_number);
00993 if (cg == 0) return CG_ERROR;
00994
00995 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
00996
00997 discrete = cgi_get_discrete(cg, B, Z, D);
00998 if (discrete==0) return CG_ERROR;
00999
01000 strcpy(discrete_name, discrete->name);
01001
01002 return CG_OK;
01003 }
01004
01005
01006
01007 int cg_ngrids(int file_number, int B, int Z, int *ngrids) {
01008 cgns_zone *zone;
01009
01010 cg = cgi_get_file(file_number);
01011 if (cg == 0) return CG_ERROR;
01012
01013 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
01014
01015
01016 zone = cgi_get_zone(cg, B, Z);
01017 if (zone==0) return CG_ERROR;
01018
01019 (*ngrids) = zone->nzcoor;
01020 return CG_OK;
01021 }
01022
01023 int cg_grid_read(int file_number, int B, int Z, int G, char *gridname) {
01024 cgns_zcoor *zcoor;
01025
01026 cg = cgi_get_file(file_number);
01027 if (cg == 0) return CG_ERROR;
01028
01029 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
01030
01031
01032 zcoor = cgi_get_zcoor(cg, B, Z, G);
01033 if (zcoor==0) return CG_ERROR;
01034
01035
01036 strcpy(gridname,zcoor->name);
01037 return CG_OK;
01038 }
01039
01040
01041
01042
01043 int cg_ncoords(int file_number, int B, int Z, int *ncoords) {
01044 cgns_zcoor *zcoor;
01045
01046 cg = cgi_get_file(file_number);
01047 if (cg == 0) return CG_ERROR;
01048
01049 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
01050
01051
01052 zcoor = cgi_get_zcoorGC(cg, B, Z);
01053 if (zcoor==0) *ncoords = 0;
01054 else *ncoords = zcoor->ncoords;
01055 return CG_OK;
01056 }
01057
01058 int cg_coord_info(int file_number, int B, int Z, int C, DataType_t *type, char *coordname) {
01059 cgns_zcoor *zcoor;
01060
01061 cg = cgi_get_file(file_number);
01062 if (cg == 0) return CG_ERROR;
01063
01064 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
01065
01066
01067 zcoor = cgi_get_zcoorGC(cg, B, Z);
01068 if (zcoor==0) return CG_ERROR;
01069
01070 if (C>zcoor->ncoords || C<=0) {
01071 cgi_error("coord number %d invalid",C);
01072 return CG_ERROR;
01073 }
01074 *type = cgi_datatype(zcoor->coord[C-1].data_type);
01075 strcpy(coordname, zcoor->coord[C-1].name);
01076
01077 return CG_OK;
01078 }
01079
01080 int cg_coord_read(int file_number, int B, int Z, char const * coordname, DataType_t type,
01081 int const * rmin, int const * rmax, void *coord_ptr) {
01082 cgns_zcoor *zcoor;
01083 cgns_array *coord;
01084 int n, num=1, pos, i, j, k, c;
01085 void *xyz;
01086 int imin[3], imax[3];
01087 int read_full_range=1;
01088 int npt=0;
01089 int index_dim;
01090
01091
01092
01093
01094
01095
01096
01097 if (type!=RealSingle && type!=RealDouble) {
01098 cgi_error("Invalid data type for coord. array: %d",type);
01099 return CG_ERROR;
01100 }
01101
01102 cg = cgi_get_file(file_number);
01103 if (cg == 0) return CG_ERROR;
01104
01105 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
01106
01107
01108 zcoor = cgi_get_zcoorGC(cg, B, Z);
01109 if (zcoor==0) return CG_ERROR;
01110
01111
01112 coord = 0;
01113 for (c=0; c<zcoor->ncoords; c++) {
01114 if (strcmp(zcoor->coord[c].name, coordname)==0) {
01115 coord = &zcoor->coord[c];
01116 break;
01117 }
01118 }
01119 if (coord==0) {
01120 cgi_error("Coordinate %s not found.",coordname);
01121 return CG_NODE_NOT_FOUND;
01122 }
01123
01124
01125 index_dim=cg->base[B-1].zone[Z-1].index_dim;
01126 num = 1;
01127 for (n=0; n<index_dim; n++) num *= coord->dim_vals[n];
01128
01129
01130 for (n=0; n<index_dim; n++) {
01131 if (rmax[n] > coord->dim_vals[n] || rmin[n]<1) {
01132 cgi_error("Invalid range of data requested");
01133 return CG_ERROR;
01134 }
01135 }
01136
01137
01138 for (n=0; n<index_dim; n++) {
01139 if (rmin[n]!=1 || rmax[n] != coord->dim_vals[n]) {
01140 read_full_range=0;
01141 break;
01142 }
01143 }
01144
01145
01146
01147 if ((xyz=(void *)malloc(num*size_of(coord->data_type)))==NULL) {
01148 cgi_error("Error allocating xyz");
01149 return CG_ERROR;
01150 }
01151 if (cgio_read_all_data(cg->cgio, coord->id, xyz)) {
01152 cg_io_error("cgio_read_all_data");
01153 return CG_ERROR;
01154 }
01155
01156 if (read_full_range && type==cgi_datatype(coord->data_type)) {
01157 memcpy(coord_ptr, xyz, num*size_of(coord->data_type));
01158
01159 } else {
01160
01161 for (n=0; n<index_dim; n++) {
01162 imin[n]=rmin[n];
01163 imax[n]=rmax[n];
01164 }
01165 for (n=index_dim; n<3; n++) imin[n]=imax[n]=1;
01166
01167
01168 npt=0;
01169
01170
01171 if (type==RealSingle && cgi_datatype(coord->data_type)==RealSingle) {
01172 for (k=imin[2]-1; k<imax[2]; k++)
01173 for (j=imin[1]-1; j<imax[1]; j++)
01174 for (i=imin[0]-1; i<imax[0]; i++) {
01175 pos = i + j*coord->dim_vals[0] + k*coord->dim_vals[0]*coord->dim_vals[1];
01176 *((float *) coord_ptr+npt) = *((float *) xyz+pos);
01177 npt++;
01178 }
01179
01180 } else if (type==RealSingle && cgi_datatype(coord->data_type)==RealDouble) {
01181 for (k=imin[2]-1; k<imax[2]; k++)
01182 for (j=imin[1]-1; j<imax[1]; j++)
01183 for (i=imin[0]-1; i<imax[0]; i++) {
01184 pos = i + j*coord->dim_vals[0] + k*coord->dim_vals[0]*coord->dim_vals[1];
01185 *((float *) coord_ptr+npt) = (float)(*((double *) xyz+pos));
01186 npt++;
01187 }
01188
01189 } else if (type==RealDouble && cgi_datatype(coord->data_type)==RealSingle) {
01190 for (k=imin[2]-1; k<imax[2]; k++)
01191 for (j=imin[1]-1; j<imax[1]; j++)
01192 for (i=imin[0]-1; i<imax[0]; i++) {
01193 pos = i + j*coord->dim_vals[0] + k*coord->dim_vals[0]*coord->dim_vals[1];
01194 *((double *) coord_ptr+npt) = (double)(*((float *) xyz+pos));
01195 npt++;
01196 }
01197
01198 } else if (type==RealDouble && cgi_datatype(coord->data_type)==RealDouble) {
01199 for (k=imin[2]-1; k<imax[2]; k++)
01200 for (j=imin[1]-1; j<imax[1]; j++)
01201 for (i=imin[0]-1; i<imax[0]; i++) {
01202 pos = i + j*coord->dim_vals[0] + k*coord->dim_vals[0]*coord->dim_vals[1];
01203 *((double *) coord_ptr+npt) = *((double *) xyz+pos);
01204 npt++;
01205 }
01206 }
01207 }
01208 free(xyz);
01209 return CG_OK;
01210 }
01211
01212 int cg_coord_id(int file_number, int B, int Z, int C, double *coord_id) {
01213 cgns_zcoor *zcoor;
01214
01215 cg = cgi_get_file(file_number);
01216 if (cg == 0) return CG_ERROR;
01217
01218 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
01219
01220
01221 zcoor = cgi_get_zcoorGC(cg, B, Z);
01222 if (zcoor==0) return CG_ERROR;
01223
01224 if (C>zcoor->ncoords || C<=0) {
01225 cgi_error("coord number %d invalid",C);
01226 return CG_ERROR;
01227 }
01228
01229 *coord_id = zcoor->coord[C-1].id;
01230 return CG_OK;
01231 }
01232
01233
01234
01235
01236
01237 int cg_nsections(int file_number, int B, int Z, int *nsections) {
01238 cgns_zone *zone;
01239
01240 cg = cgi_get_file(file_number);
01241 if (cg == 0) return CG_ERROR;
01242
01243
01244 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
01245
01246 zone = cgi_get_zone(cg, B, Z);
01247 if (zone==0) return CG_ERROR;
01248
01249 (*nsections) = zone->nsections;
01250 return CG_OK;
01251 }
01252
01253 int cg_section_read(int file_number, int B, int Z, int S, char *SectionName,
01254 ElementType_t *type, int *start, int *end, int *nbndry, int *parent_flag) {
01255 cgns_section *section;
01256
01257 cg = cgi_get_file(file_number);
01258 if (cg == 0) return CG_ERROR;
01259
01260
01261 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
01262
01263 section = cgi_get_section(cg, B, Z, S);
01264 if (section == 0) return CG_ERROR;
01265
01266 strcpy(SectionName, section->name);
01267 *type = section->el_type;
01268 *start = section->range[0];
01269 *end = section->range[1];
01270 *nbndry = section->el_bound;
01271 if (section->parent) *parent_flag=1;
01272 else *parent_flag=0;
01273 return CG_OK;
01274 }
01275
01276
01277
01278
01279 int cg_ElementDataSize(int file_number, int B, int Z, int S, int *ElementDataSize) {
01280
01281 cgns_section *section;
01282
01283 cg = cgi_get_file(file_number);
01284 if (cg == 0) return CG_ERROR;
01285
01286
01287 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
01288
01289 section = cgi_get_section(cg, B, Z, S);
01290 if (section == 0) return CG_ERROR;
01291
01292 *ElementDataSize = section->connect->dim_vals[0];
01293 return CG_OK;
01294 }
01295
01296 int cg_elements_read(int file_number, int B, int Z, int S, int *elements,
01297 int *parent_data) {
01298 cgns_section *section;
01299 int count, num, ElementDataSize=0;
01300
01301 cg = cgi_get_file(file_number);
01302 if (cg == 0) return CG_ERROR;
01303
01304
01305 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
01306
01307 section = cgi_get_section(cg, B, Z, S);
01308 if (section == 0) return CG_ERROR;
01309
01310
01311 ElementDataSize = section->connect->dim_vals[0];
01312
01313
01314 num = section->range[1] - section->range[0] +1;
01315 count = cgi_element_data_size(section->el_type, num, section->connect->data);
01316 if (count < 0) return CG_ERROR;
01317 if (count != ElementDataSize) {
01318 cgi_error("Error in recorded element connectivity array...");
01319 return CG_ERROR;
01320 }
01321
01322 memcpy(elements, (int *)section->connect->data, ElementDataSize*sizeof(int));
01323
01324 if (section->parent && parent_data) {
01325 memcpy(parent_data, section->parent->data, num*4*sizeof(int));
01326 }
01327 return CG_OK;
01328 }
01329
01330
01331
01332
01333 int cg_nsols(int file_number, int B, int Z, int *nsols) {
01334 cgns_zone *zone;
01335
01336 cg = cgi_get_file(file_number);
01337 if (cg == 0) return CG_ERROR;
01338
01339 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
01340
01341 zone = cgi_get_zone(cg, B, Z);
01342 if (zone==0) return CG_ERROR;
01343
01344 *nsols = zone->nsols;
01345 return CG_OK;
01346 }
01347
01348 int cg_sol_info(int file_number, int B, int Z, int S, char *solname,
01349 GridLocation_t *location) {
01350 cgns_sol *sol;
01351
01352 cg = cgi_get_file(file_number);
01353 if (cg == 0) return CG_ERROR;
01354
01355 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
01356
01357 sol = cgi_get_sol(cg, B, Z, S);
01358 if (sol==0) return CG_ERROR;
01359
01360 strcpy(solname, sol->name);
01361 *location = sol->location;
01362 return CG_OK;
01363 }
01364
01365 int cg_sol_id(int file_number, int B, int Z, int S, double *sol_id) {
01366 cgns_sol *sol;
01367
01368 cg = cgi_get_file(file_number);
01369 if (cg == 0) return CG_ERROR;
01370
01371 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
01372
01373 sol = cgi_get_sol(cg, B, Z, S);
01374 if (sol==0) return CG_ERROR;
01375
01376 *sol_id = sol->id;
01377 return CG_OK;
01378 }
01379
01380
01381
01382
01383 int cg_nfields(int file_number, int B, int Z, int S, int *nfields) {
01384 cgns_sol *sol;
01385
01386 cg = cgi_get_file(file_number);
01387 if (cg == 0) return CG_ERROR;
01388
01389 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
01390
01391 sol = cgi_get_sol(cg, B, Z, S);
01392 if (sol==0) return CG_ERROR;
01393
01394 *nfields = sol->nfields;
01395 return CG_OK;
01396 }
01397
01398 int cg_field_info(int file_number, int B, int Z, int S, int F, DataType_t *type,
01399 char *fieldname) {
01400 cgns_array *field;
01401
01402 cg = cgi_get_file(file_number);
01403 if (cg == 0) return CG_ERROR;
01404
01405 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
01406
01407 field = cgi_get_field(cg, B, Z, S, F);
01408 if (field==0) return CG_ERROR;
01409
01410 strcpy(fieldname, field->name);
01411 *type = cgi_datatype(field->data_type);
01412
01413 return CG_OK;
01414 }
01415
01416 int cg_field_read(int file_number, int B, int Z, int S, char *fieldname, DataType_t type,
01417 int *rmin, int *rmax, void *field_ptr) {
01418 cgns_sol *sol;
01419 cgns_array *field;
01420 int n, num=1, pos, i, j, k, f;
01421 void *values;
01422 int imin[3], imax[3];
01423 int read_full_range=1;
01424 int index_dim;
01425
01426
01427
01428
01429
01430
01431 if (type<0 || type>=NofValidDataTypes) {
01432 cgi_error("Invalid data type requested for flow solution: %d",type);
01433 return CG_ERROR;
01434 }
01435 cg = cgi_get_file(file_number);
01436 if (cg == 0) return CG_ERROR;
01437
01438 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
01439
01440 sol = cgi_get_sol(cg, B, Z, S);
01441 if (sol==0) return CG_ERROR;
01442 field = 0;
01443 for (f=0; f<sol->nfields; f++) {
01444 if (strcmp(sol->field[f].name, fieldname)==0) {
01445 field = cgi_get_field(cg, B, Z, S, f+1);
01446 if (field==0) return CG_ERROR;
01447 break;
01448 }
01449 }
01450 if (field==0) {
01451 cgi_error("Flow solution array %s not found",fieldname);
01452 return CG_NODE_NOT_FOUND;
01453 }
01454
01455
01456 index_dim=cg->base[B-1].zone[Z-1].index_dim;
01457 num =1;
01458 for (n=0; n<index_dim; n++) num *= field->dim_vals[n];
01459
01460
01461 for (n=0; n<index_dim; n++) {
01462 if (rmax[n] > field->dim_vals[n] || rmin[n]<1) {
01463 cgi_error("Invalid range of data requested");
01464 return CG_ERROR;
01465 }
01466 }
01467
01468
01469 for (n=0; n<index_dim; n++) {
01470 if (rmin[n]!=1 || rmax[n] != field->dim_vals[n]) {
01471 read_full_range=0;
01472 break;
01473 }
01474 }
01475
01476
01477
01478 if ((values=(void *)malloc(num*size_of(field->data_type)))==NULL) {
01479 cgi_error("Error allocating values");
01480 return CG_ERROR;
01481 }
01482 if (cgio_read_all_data(cg->cgio, field->id, values)) {
01483 cg_io_error("cgio_read_all_data");
01484 return CG_ERROR;
01485 }
01486
01487 if (read_full_range && type == cgi_datatype(field->data_type)) {
01488 memcpy(field_ptr, values, num*size_of(field->data_type));
01489
01490 } else {
01491
01492 for (n=0; n<index_dim; n++) {
01493 imin[n]=rmin[n];
01494 imax[n]=rmax[n];
01495 }
01496 for (n=index_dim; n<3; n++) imin[n]=imax[n]=1;
01497
01498
01499 n=0;
01500
01501
01502 if (type==Integer && cgi_datatype(field->data_type)==Integer) {
01503 for (k=imin[2]-1; k<imax[2]; k++)
01504 for (j=imin[1]-1; j<imax[1]; j++)
01505 for (i=imin[0]-1; i<imax[0]; i++) {
01506 pos = i + j*field->dim_vals[0] + k*field->dim_vals[0]*field->dim_vals[1];
01507 *((int *) field_ptr+n) = *((int *) values+pos);
01508 n++;
01509 }
01510
01511 } else if (type==Integer && cgi_datatype(field->data_type)==RealSingle) {
01512 for (k=imin[2]-1; k<imax[2]; k++)
01513 for (j=imin[1]-1; j<imax[1]; j++)
01514 for (i=imin[0]-1; i<imax[0]; i++) {
01515 pos = i + j*field->dim_vals[0] + k*field->dim_vals[0]*field->dim_vals[1];
01516 *((int *) field_ptr+n) = (int) (*((float *) values+pos));
01517 n++;
01518 }
01519
01520 } else if (type==Integer && cgi_datatype(field->data_type)==RealDouble) {
01521 for (k=imin[2]-1; k<imax[2]; k++)
01522 for (j=imin[1]-1; j<imax[1]; j++)
01523 for (i=imin[0]-1; i<imax[0]; i++) {
01524 pos = i + j*field->dim_vals[0] + k*field->dim_vals[0]*field->dim_vals[1];
01525 *((int *) field_ptr+n) = (int) (*((double *) values+pos));
01526 n++;
01527 }
01528
01529 } else if (type==RealSingle && cgi_datatype(field->data_type)==Integer) {
01530 for (k=imin[2]-1; k<imax[2]; k++)
01531 for (j=imin[1]-1; j<imax[1]; j++)
01532 for (i=imin[0]-1; i<imax[0]; i++) {
01533 pos = i + j*field->dim_vals[0] + k*field->dim_vals[0]*field->dim_vals[1];
01534 *((float *) field_ptr+n) = (float) (*((int *) values+pos));
01535 n++;
01536 }
01537
01538 } else if (type==RealSingle && cgi_datatype(field->data_type)==RealSingle) {
01539 for (k=imin[2]-1; k<imax[2]; k++)
01540 for (j=imin[1]-1; j<imax[1]; j++)
01541 for (i=imin[0]-1; i<imax[0]; i++) {
01542 pos = i + j*field->dim_vals[0] + k*field->dim_vals[0]*field->dim_vals[1];
01543 *((float *) field_ptr+n) = *((float *) values+pos);
01544 n++;
01545 }
01546
01547 } else if (type==RealSingle && cgi_datatype(field->data_type)==RealDouble) {
01548 for (k=imin[2]-1; k<imax[2]; k++)
01549 for (j=imin[1]-1; j<imax[1]; j++)
01550 for (i=imin[0]-1; i<imax[0]; i++) {
01551 pos = i + j*field->dim_vals[0] + k*field->dim_vals[0]*field->dim_vals[1];
01552 *((float *) field_ptr+n) = (float)(*((double *) values+pos));
01553 n++;
01554 }
01555
01556 } else if (type==RealDouble && cgi_datatype(field->data_type)==Integer) {
01557 for (k=imin[2]-1; k<imax[2]; k++)
01558 for (j=imin[1]-1; j<imax[1]; j++)
01559 for (i=imin[0]-1; i<imax[0]; i++) {
01560 pos = i + j*field->dim_vals[0] + k*field->dim_vals[0]*field->dim_vals[1];
01561 *((double *) field_ptr+n) = (double)(*((int *) values+pos));
01562 n++;
01563 }
01564
01565 } else if (type==RealDouble && cgi_datatype(field->data_type)==RealSingle) {
01566 for (k=imin[2]-1; k<imax[2]; k++)
01567 for (j=imin[1]-1; j<imax[1]; j++)
01568 for (i=imin[0]-1; i<imax[0]; i++) {
01569 pos = i + j*field->dim_vals[0] + k*field->dim_vals[0]*field->dim_vals[1];
01570 *((double *) field_ptr+n) = (double)(*((float *) values+pos));
01571 n++;
01572 }
01573
01574 } else if (type==RealDouble && cgi_datatype(field->data_type)==RealDouble) {
01575 for (k=imin[2]-1; k<imax[2]; k++)
01576 for (j=imin[1]-1; j<imax[1]; j++)
01577 for (i=imin[0]-1; i<imax[0]; i++) {
01578 pos = i + j*field->dim_vals[0] + k*field->dim_vals[0]*field->dim_vals[1];
01579 *((double *) field_ptr+n) = *((double *) values+pos);
01580 n++;
01581 }
01582 }
01583 }
01584 free(values);
01585
01586 return CG_OK;
01587 }
01588
01589 int cg_field_id(int file_number, int B, int Z, int S, int F, double *field_id) {
01590 cgns_array *field;
01591
01592 cg = cgi_get_file(file_number);
01593 if (cg == 0) return CG_ERROR;
01594
01595 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
01596
01597 field = cgi_get_field(cg, B, Z, S, F);
01598 if (field==0) return CG_ERROR;
01599
01600 *field_id = field->id;
01601 return CG_OK;
01602 }
01603
01604
01605
01606
01607
01608 int cg_nholes(int file_number, int B, int Z, int *nholes) {
01609 cgns_zconn *zconn;
01610
01611 cg = cgi_get_file(file_number);
01612 if (cg == 0) return CG_ERROR;
01613
01614 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
01615
01616 zconn = cgi_get_zconn(cg, B, Z);
01617 if (zconn==0) *nholes = 0;
01618 else *nholes = zconn->nholes;
01619 return CG_OK;
01620 }
01621
01622 int cg_hole_info(int file_number, int B, int Z, int I, char *holename,
01623 GridLocation_t *location, PointSetType_t *ptset_type, int *nptsets,
01624 int *npnts) {
01625
01626 cgns_hole *hole;
01627
01628 cg = cgi_get_file(file_number);
01629 if (cg == 0) return CG_ERROR;
01630
01631 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
01632
01633 hole = cgi_get_hole(cg, B, Z, I);
01634 if (hole==0) return CG_ERROR;
01635
01636 strcpy(holename, hole->name);
01637 *location = hole->location;
01638 *ptset_type = hole->nptsets ? hole->ptset[0].type : PointSetTypeNull;
01639 *nptsets = hole->nptsets;
01640
01641 if (hole->nptsets==1) *npnts = hole->ptset[0].npts;
01642 else *npnts = 2*hole->nptsets;
01643 return CG_OK;
01644 }
01645
01646 int cg_hole_read(int file_number, int B, int Z, int I, int *pnts) {
01647 cgns_hole *hole;
01648 int set, index_dim;
01649
01650 cg = cgi_get_file(file_number);
01651 if (cg == 0) return CG_ERROR;
01652
01653 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
01654
01655 hole = cgi_get_hole(cg, B, Z, I);
01656 if (hole==0) return CG_ERROR;
01657
01658 index_dim = cg->base[B-1].zone[Z-1].index_dim;
01659
01660
01661 for (set=0; set<hole->nptsets; set++) {
01662 if (hole->ptset[set].npts>0) {
01663 if (cgio_read_all_data(cg->cgio, hole->ptset[set].id,
01664 (void *)((int *)pnts+2*index_dim*set))) {
01665 cg_io_error("cgio_read_all_data");
01666 return CG_ERROR;
01667 }
01668 } else {
01669 cgi_warning("Overset hole #%d set %d, of zone #%d, base #%d, contains no points",
01670 I, set, Z, B);
01671 }
01672 }
01673
01674 return CG_OK;
01675 }
01676
01677 int cg_hole_id(int file_number, int B, int Z, int I, double *hole_id) {
01678 cgns_hole *hole;
01679
01680 cg = cgi_get_file(file_number);
01681 if (cg == 0) return CG_ERROR;
01682
01683 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
01684
01685 hole = cgi_get_hole(cg, B, Z, I);
01686 if (hole==0) return CG_ERROR;
01687
01688 *hole_id = hole->id;
01689 return CG_OK;
01690 }
01691
01692
01693
01694
01695
01696 int cg_nconns(int file_number, int B, int Z, int *nconns) {
01697 cgns_zconn *zconn;
01698
01699 cg = cgi_get_file(file_number);
01700 if (cg == 0) return CG_ERROR;
01701
01702 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
01703
01704 zconn = cgi_get_zconn(cg, B, Z);
01705 if (zconn==0) *nconns = 0;
01706 else *nconns = zconn->nconns;
01707 return CG_OK;
01708 }
01709
01710
01711
01712
01713 int cg_conn_info(int file_number, int B, int Z, int I, char *connectname,
01714 GridLocation_t *location, GridConnectivityType_t *type,
01715 PointSetType_t *ptset_type, int *npnts, char *donorname,
01716 ZoneType_t *donor_zonetype, PointSetType_t *donor_ptset_type,
01717 DataType_t *donor_datatype, int *ndata_donor) {
01718
01719 int dZ;
01720 cgns_conn *conn;
01721
01722 cg = cgi_get_file(file_number);
01723 if (cg == 0) return CG_ERROR;
01724
01725 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
01726
01727 conn = cgi_get_conn(cg, B, Z, I);
01728 if (conn==0) return CG_ERROR;
01729
01730 strcpy(connectname, conn->name);
01731 *type = conn->type;
01732 *location = conn->location;
01733 *ptset_type = conn->ptset.type;
01734 *npnts = conn->ptset.npts;
01735
01736
01737 strcpy(donorname, conn->donor);
01738 *donor_datatype = cgi_datatype(conn->dptset.data_type);
01739 *ndata_donor = conn->dptset.npts;
01740 *donor_ptset_type = conn->dptset.type;
01741
01742
01743 *donor_zonetype = ZoneTypeNull;
01744
01745 for (dZ=0; dZ<cg->base[B-1].nzones; dZ++) {
01746 if (strcmp(cg->base[B-1].zone[dZ].name,donorname)==0) {
01747 *donor_zonetype = cg->base[B-1].zone[dZ].type;
01748 break;
01749 }
01750 }
01751 if (*donor_zonetype == 0) {
01752 cgi_error("cg_conn_info:donor zone %s does not exist",donorname);
01753 return CG_ERROR;
01754 }
01755 return CG_OK;
01756 }
01757
01758
01759
01760
01761 int cg_conn_read(int file_number, int B, int Z, int I, int *pnts,
01762 DataType_t donor_datatype, void *donor_data) {
01763 char_33 data_type;
01764 cgns_conn *conn;
01765 void *dpnts;
01766 int n, size, cell_dim;
01767
01768
01769 if (donor_data != NULL && donor_datatype!=Integer &&
01770 donor_datatype!=RealSingle && donor_datatype!=RealDouble) {
01771 cgi_error("Invalid datatype requested for a point set: %d", donor_datatype);
01772 return CG_ERROR;
01773 }
01774
01775
01776 cg = cgi_get_file(file_number);
01777 if (cg == 0) return CG_ERROR;
01778
01779 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
01780
01781 conn = cgi_get_conn(cg, B, Z, I);
01782 if (conn==0) return CG_ERROR;
01783
01784 cell_dim = cg->base[B-1].cell_dim;
01785
01786
01787 if (conn->ptset.npts>0) {
01788 if (cgio_read_all_data(cg->cgio, conn->ptset.id, (void *)pnts)) {
01789 cg_io_error("cgio_read_all_data");
01790 return CG_ERROR;
01791 }
01792 } else {
01793 cgi_warning("Interface receiver patch #%d of zone #%d, base #%d, contains no points",
01794 I, Z, B);
01795 }
01796
01797 if (donor_data == NULL) return CG_OK;
01798
01799
01800 if (conn->dptset.npts>0) {
01801 cgns_ptset dptset = conn->dptset;
01802 int index_dim = 0;
01803 for (n=0; n<cg->base[B-1].nzones; n++) {
01804 if (strcmp(cg->base[B-1].zone[n].name,conn->donor)==0) {
01805 index_dim = cg->base[B-1].zone[n].type == Structured ? cell_dim : 1;
01806 break;
01807 }
01808 }
01809 if (index_dim == 0) {
01810 cgi_error("cg_conn_read:donor zone %s does not exist",conn->donor);
01811 return CG_ERROR;
01812 }
01813 size = index_dim*dptset.npts;
01814 if ((dpnts=(void *)malloc(size*size_of(dptset.data_type)))==NULL) {
01815 cgi_error("Error allocating dpnts...");
01816 return CG_ERROR;
01817 }
01818 if (cgio_read_all_data(cg->cgio, dptset.id, dpnts)) {
01819 cg_io_error("cgio_read_all_data");
01820 return CG_ERROR;
01821 }
01822 strcpy(data_type, dptset.data_type);
01823 } else {
01824 cgi_warning("Interface donor patch #%d of zone #%d, base #%d, contains no points",
01825 I, Z, B);
01826 return CG_OK;
01827 }
01828
01829
01830 if (donor_datatype==Integer && cgi_datatype(data_type)==Integer) {
01831 for (n=0; n<size; n++)
01832 *((int *)donor_data+n) = *((int *)dpnts+n);
01833
01834 } else if (donor_datatype==Integer && cgi_datatype(data_type)==RealSingle) {
01835 for (n=0; n<size; n++)
01836 *((int *)donor_data+n) = (int)(*((float *)dpnts+n));
01837
01838 } else if (donor_datatype==Integer && cgi_datatype(data_type)==RealDouble) {
01839 for (n=0; n<size; n++)
01840 *((int *)donor_data+n) = (int)(*((double *)dpnts+n));
01841
01842 } else if (donor_datatype==RealSingle && cgi_datatype(data_type)==Integer) {
01843 for (n=0; n<size; n++)
01844 *((float *)donor_data+n) = (float)(*((int *)dpnts+n));
01845
01846 } else if (donor_datatype==RealSingle && cgi_datatype(data_type)==RealSingle) {
01847 for (n=0; n<size; n++)
01848 *((float *)donor_data+n) = *((float *)dpnts+n);
01849
01850 } else if (donor_datatype==RealSingle && cgi_datatype(data_type)==RealDouble) {
01851 for (n=0; n<size; n++)
01852 *((float *)donor_data+n) = (float)(*((double *)dpnts+n));
01853
01854 } else if (donor_datatype==RealDouble && cgi_datatype(data_type)==Integer) {
01855 for (n=0; n<size; n++)
01856 *((double *)donor_data+n) = (double)(*((int *)dpnts+n));
01857
01858 } else if (donor_datatype==RealDouble && cgi_datatype(data_type)==RealSingle) {
01859 for (n=0; n<size; n++)
01860 *((double *)donor_data+n) = (double)(*((float *)dpnts+n));
01861
01862 } else if (donor_datatype==RealDouble && cgi_datatype(data_type)==RealDouble) {
01863 for (n=0; n<size; n++)
01864 *((double *)donor_data+n) = *((double *)dpnts+n);
01865 }
01866 free(dpnts);
01867
01868 return CG_OK;
01869 }
01870
01871 int cg_conn_read_short(int file_number, int B, int Z, int I, int *pnts) {
01872 #if 0
01873 cgns_conn *conn;
01874 int ierr, cell_dim;
01875
01876
01877 cg = cgi_get_file(file_number);
01878 if (cg == 0) return CG_ERROR;
01879
01880 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
01881
01882 conn = cgi_get_conn(cg, B, Z, I);
01883 if (conn==0) return CG_ERROR;
01884
01885 cell_dim = cg->base[B-1].cell_dim;
01886
01887
01888 if (conn->ptset.npts>0) {
01889 if (cgio_read_all_data(cg->cgio, conn->ptset.id, (void *)pnts)) {
01890 cg_io_error("cgio_read_all_data");
01891 return CG_ERROR;
01892 }
01893 } else {
01894 cgi_warning("Interface receiver patch #%d of zone #%d, base #%d, contains no points",
01895 I, Z, B);
01896 }
01897
01898 return CG_OK;
01899 #else
01900 return cg_conn_read(file_number, B, Z, I, pnts, DataTypeNull, NULL);
01901 #endif
01902 }
01903
01904 int cg_conn_id(int file_number, int B, int Z, int I, double *conn_id) {
01905 cgns_conn *conn;
01906
01907 cg = cgi_get_file(file_number);
01908 if (cg == 0) return CG_ERROR;
01909
01910 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
01911
01912 conn = cgi_get_conn(cg, B, Z, I);
01913 if (conn==0) return CG_ERROR;
01914
01915 *conn_id = conn->id;
01916 return CG_OK;
01917 }
01918
01919
01920
01921
01922
01923 int cg_n1to1(int file_number, int B, int Z, int *n1to1) {
01924 cgns_zconn *zconn;
01925
01926 cg = cgi_get_file(file_number);
01927 if (cg == 0) return CG_ERROR;
01928
01929 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
01930
01931 zconn = cgi_get_zconn(cg, B, Z);
01932 if (zconn==0) *n1to1 = 0;
01933 else *n1to1 = zconn->n1to1;
01934 return CG_OK;
01935 }
01936
01937 int cg_n1to1_global(int file_number, int B, int *n1to1_global) {
01938 cgns_base *base;
01939 cgns_zone *zone;
01940 cgns_zconn *zconn;
01941 int Z, I, D;
01942 int_3 transform;
01943 int_6 donor_range, range;
01944 char_33 connectname, donorname;
01945
01946 int ndouble=0;
01947 char_33 *Dzonename = 0;
01948 int_6 *Drange = 0, *Ddonor_range = 0;
01949 int index_dim;
01950
01951 cg = cgi_get_file(file_number);
01952 if (cg == 0) return CG_ERROR;
01953
01954 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
01955
01956 base = cgi_get_base(cg, B);
01957 if (base==0) return CG_ERROR;
01958
01959 *n1to1_global = 0;
01960 for (Z=1; Z<=base->nzones; Z++) {
01961 zone = cgi_get_zone(cg, B, Z);
01962 if (zone==0) return CG_ERROR;
01963 index_dim = zone->index_dim;
01964 zconn = cgi_get_zconn(cg, B, Z);
01965 if (zconn==0) continue;
01966 if (zconn->n1to1 ==0) continue;
01967 for (I=1; I<=zconn->n1to1; I++) {
01968 if (cg_1to1_read(file_number, B, Z, I, connectname, donorname,
01969 range, donor_range, transform)) return CG_ERROR;
01970 if (cgi_zone_no(base, donorname, &D)) return CG_ERROR;
01971
01972
01973 if (Z<D) (*n1to1_global)++;
01974
01975
01976 if (Z==D) {
01977
01978 if (cgi_add_czone(zone->name, range, donor_range, index_dim,
01979 &ndouble, &Dzonename, &Drange, &Ddonor_range)) {
01980 (*n1to1_global)++;
01981 }
01982 }
01983 }
01984 }
01985 if (Dzonename) free(Dzonename);
01986 if (Drange) free(Drange);
01987 if (Ddonor_range) free(Ddonor_range);
01988
01989 return CG_OK;
01990 }
01991
01992
01993 int cg_1to1_read(int file_number, int B, int Z, int I, char *connectname,
01994 char *donorname, int *range, int *donor_range, int *transform) {
01995 cgns_1to1 *one21;
01996 int i, index_dim;
01997
01998
01999
02000
02001
02002
02003 cg = cgi_get_file(file_number);
02004 if (cg == 0) return CG_ERROR;
02005
02006 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
02007
02008 one21 = cgi_get_1to1(cg, B, Z, I);
02009 if (one21==0) return CG_ERROR;
02010
02011
02012 if (one21->ptset.npts > 0) {
02013 if (cgio_read_all_data(cg->cgio, one21->ptset.id, (void *)range)) {
02014 cg_io_error("cgio_read_all_data");
02015 return CG_ERROR;
02016 }
02017 } else {
02018 cgi_warning("1to1 interface %d (receiver side) for zone %d base % is undefined",
02019 I,Z,B);
02020 }
02021
02022
02023 if (one21->dptset.npts > 0) {
02024 if (cgio_read_all_data(cg->cgio, one21->dptset.id,
02025 (void *)donor_range)) {
02026 cg_io_error("cgio_read_all_data");
02027 return CG_ERROR;
02028 }
02029 } else {
02030 cgi_warning("1to1 interface %d (donor side) for zone %d base % is undefined",
02031 I,Z,B);
02032 }
02033
02034
02035 index_dim = cg->base[B-1].zone[Z-1].index_dim;
02036 for (i=0; i<index_dim; i++) transform[i] = one21->transform[i];
02037
02038 strcpy(connectname, one21->name);
02039 strcpy(donorname, one21->donor);
02040 return CG_OK;
02041 }
02042
02043 int cg_1to1_read_global(int file_number, int B, char **connectname, char **zonename,
02044 char **donorname, int **range, int **donor_range, int **transform){
02045
02046 cgns_base *base;
02047 cgns_zone *zone;
02048 cgns_zconn *zconn;
02049 int Z, I, D, n=0, j, index_dim;
02050 char connect[33], donor[33];
02051 int rang[6], drang[6], trans[6];
02052
02053 int ndouble=0;
02054 char_33 *Dzonename = 0;
02055 int_6 *Drange = 0, *Ddonor_range = 0;
02056
02057 cg = cgi_get_file(file_number);
02058 if (cg == 0) return CG_ERROR;
02059
02060 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
02061
02062 base = cgi_get_base(cg, B);
02063 if (base==0) return CG_ERROR;
02064
02065 for (Z=1; Z<=base->nzones; Z++) {
02066 zone = cgi_get_zone(cg, B, Z);
02067 if (zone->type==Unstructured) {
02068 cgi_error("GridConnectivity1to1 is only applicable to structured zones.");
02069 return CG_ERROR;
02070 }
02071 index_dim = zone->index_dim;
02072 zconn = cgi_get_zconn(cg, B, Z);
02073 if (zconn==0) continue;
02074 if (zconn->n1to1 ==0) continue;
02075 for (I=1; I<=zconn->n1to1; I++) {
02076 if (cg_1to1_read(file_number, B, Z, I, connect, donor, rang,
02077 drang, trans)) return CG_ERROR;
02078 if (cgi_zone_no(base, donor, &D)) return CG_ERROR;
02079
02080 if (Z<D || (Z==D && cgi_add_czone(zone->name, rang, drang, index_dim,
02081 &ndouble, &Dzonename, &Drange, &Ddonor_range))) {
02082 strcpy(connectname[n], connect);
02083 strcpy(zonename[n],zone->name);
02084 strcpy(donorname[n], donor);
02085 for (j=0; j<index_dim; j++) {
02086 range[n][j]= rang[j];
02087 range[n][j+index_dim]= rang[j+index_dim];
02088 donor_range[n][j]= drang[j];
02089 donor_range[n][j+index_dim]= drang[j+index_dim];
02090 transform[n][j] = trans[j];
02091 }
02092 n++;
02093 }
02094 }
02095 }
02096 if (Dzonename) free(Dzonename);
02097 if (Drange) free(Drange);
02098 if (Ddonor_range) free(Ddonor_range);
02099 return CG_OK;
02100 }
02101
02102 int cg_1to1_id(int file_number, int B, int Z, int I, double *one21_id) {
02103 cgns_1to1 *one21;
02104
02105 cg = cgi_get_file(file_number);
02106 if (cg == 0) return CG_ERROR;
02107
02108 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
02109
02110 one21 = cgi_get_1to1(cg, B, Z, I);
02111 if (one21==0) return CG_ERROR;
02112
02113 *one21_id = one21->id;
02114 return CG_OK;
02115 }
02116
02117
02118
02119
02120
02121 int cg_nbocos(int file_number, int B, int Z, int *nbocos) {
02122 cgns_zboco *zboco;
02123
02124 cg = cgi_get_file(file_number);
02125 if (cg == 0) return CG_ERROR;
02126
02127 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
02128
02129 zboco = cgi_get_zboco(cg, B, Z);
02130 if (zboco==0) *nbocos = 0;
02131 else *nbocos = zboco->nbocos;
02132 return CG_OK;
02133 }
02134
02135 int cg_boco_info(int file_number, int B, int Z, int BC, char *boconame,
02136 BCType_t *bocotype, PointSetType_t *ptset_type, int *npnts,
02137 int *NormalIndex, int *NormalListFlag, DataType_t *NormalDataType,
02138 int *ndataset) {
02139
02140 cgns_boco *boco;
02141 int n, index_dim;
02142
02143 cg = cgi_get_file(file_number);
02144 if (cg == 0) return CG_ERROR;
02145
02146 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
02147
02148 boco = cgi_get_boco(cg, B, Z, BC);
02149 if (boco==0) return CG_ERROR;
02150
02151 strcpy(boconame,boco->name);
02152 *bocotype = boco->type;
02153 if (boco->ptset) {
02154 *ptset_type = boco->ptset->type;
02155 *npnts = boco->ptset->npts;
02156 }
02157 else {
02158 *ptset_type = PointSetTypeNull;
02159 *npnts = 0;
02160 }
02161
02162 index_dim = cg->base[B-1].zone[Z-1].index_dim;
02163 if (NormalIndex) {
02164 if (boco->Nindex) {
02165 for (n=0; n<index_dim; n++)
02166 NormalIndex[n]=boco->Nindex[n];
02167 } else {
02168 for (n=0; n<index_dim; n++)
02169 NormalIndex[n]=0;
02170 }
02171 }
02172 if (boco->normal && boco->ptset) {
02173 *NormalListFlag=boco->ptset->size_of_patch*cg->base[B-1].phys_dim;
02174 *NormalDataType = cgi_datatype(boco->normal->data_type);
02175 } else {
02176 *NormalListFlag=0;
02177 *NormalDataType=DataTypeNull;
02178 }
02179 *ndataset = boco->ndataset;
02180
02181 return CG_OK;
02182 }
02183
02184 int cg_boco_read(int file_number, int B, int Z, int BC, int *pnts, void *NormalList) {
02185 cgns_boco *boco;
02186 int phys_dim;
02187
02188 cg = cgi_get_file(file_number);
02189 if (cg == 0) return CG_ERROR;
02190
02191 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
02192
02193 boco = cgi_get_boco(cg, B, Z, BC);
02194 if (boco==0) return CG_ERROR;
02195
02196
02197 if (boco->ptset && boco->ptset->npts>0) {
02198 if (cgio_read_all_data(cg->cgio, boco->ptset->id, (void *)pnts)) {
02199 cg_io_error("cgio_read_all_data");
02200 return CG_ERROR;
02201 }
02202 } else {
02203 cgi_warning("B.C. patch %d of zone %d base %d is undefined",
02204 BC, Z, B);
02205 }
02206
02207
02208 phys_dim=cg->base[B-1].phys_dim;
02209 if (NormalList && boco->normal && boco->ptset && boco->ptset->npts>0) {
02210 memcpy(NormalList, boco->normal->data,
02211 boco->ptset->size_of_patch*phys_dim*size_of(boco->normal->data_type));
02212 }
02213
02214 return CG_OK;
02215 }
02216
02217 int cg_boco_id(int file_number, int B, int Z, int BC, double *boco_id) {
02218 cgns_boco *boco;
02219
02220 cg = cgi_get_file(file_number);
02221 if (cg == 0) return CG_ERROR;
02222
02223 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
02224
02225 boco = cgi_get_boco(cg, B, Z, BC);
02226 if (boco==0) return CG_ERROR;
02227
02228 *boco_id = boco->id;
02229 return CG_OK;
02230 }
02231
02232
02233
02234
02235
02236 int cg_dataset_read(int file_number, int B, int Z, int BC, int DSet, char *name,
02237 BCType_t *BCType, int *DirichletFlag, int *NeumannFlag) {
02238
02239 cgns_dataset *dataset;
02240
02241 cg = cgi_get_file(file_number);
02242 if (cg == 0) return CG_ERROR;
02243
02244 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
02245
02246 dataset = cgi_get_dataset(cg, B, Z, BC, DSet);
02247 if (dataset==0) return CG_ERROR;
02248
02249 strcpy(name, dataset->name);
02250 *BCType = dataset->type;
02251 if (dataset->dirichlet) *DirichletFlag=1;
02252 else *DirichletFlag=0;
02253 if (dataset->neumann) *NeumannFlag=1;
02254 else *NeumannFlag=0;
02255
02256 return CG_OK;
02257 }
02258
02259
02260
02261
02262
02263 int cg_n_rigid_motions(int file_number, int B, int Z, int *n_rigid_motions) {
02264 cgns_zone *zone;
02265
02266 cg = cgi_get_file(file_number);
02267 if (cg == 0) return CG_ERROR;
02268
02269 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
02270
02271 zone = cgi_get_zone(cg, B, Z);
02272 if (zone==0) return CG_ERROR;
02273
02274 *n_rigid_motions = zone->nrmotions;
02275
02276 return CG_OK;
02277 }
02278
02279 int cg_rigid_motion_read(int file_number, int B, int Z, int R, char *name,
02280 RigidGridMotionType_t *type) {
02281
02282 cgns_rmotion *rmotion;
02283
02284 cg = cgi_get_file(file_number);
02285 if (cg == 0) return CG_ERROR;
02286
02287 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
02288
02289 rmotion = cgi_get_rmotion(cg, B, Z, R);
02290 if (rmotion==0) return CG_ERROR;
02291
02292 strcpy(name, rmotion->name);
02293 *type = rmotion->type;
02294
02295 return CG_OK;
02296 }
02297
02298
02299
02300
02301
02302 int cg_n_arbitrary_motions(int file_number, int B, int Z, int *n_arbitrary_motions) {
02303 cgns_zone *zone;
02304
02305 cg = cgi_get_file(file_number);
02306 if (cg == 0) return CG_ERROR;
02307
02308 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
02309
02310 zone = cgi_get_zone(cg, B, Z);
02311 if (zone==0) return CG_ERROR;
02312
02313 *n_arbitrary_motions = zone->namotions;
02314
02315 return CG_OK;
02316 }
02317
02318 int cg_arbitrary_motion_read(int file_number, int B, int Z, int A, char *name,
02319 ArbitraryGridMotionType_t *type) {
02320
02321 cgns_amotion *amotion;
02322
02323 cg = cgi_get_file(file_number);
02324 if (cg == 0) return CG_ERROR;
02325
02326 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
02327
02328 amotion = cgi_get_amotion(cg, B, Z, A);
02329 if (amotion==0) return CG_ERROR;
02330
02331 strcpy(name, amotion->name);
02332 *type = amotion->type;
02333
02334 return CG_OK;
02335 }
02336
02337
02338
02339
02340
02341 int cg_simulation_type_read(int file_number, int B, SimulationType_t *type) {
02342 cgns_base *base;
02343
02344 cg = cgi_get_file(file_number);
02345 if (cg == 0) return CG_ERROR;
02346
02347 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
02348
02349 base = cgi_get_base(cg, B);
02350 if (base==0) return CG_ERROR;
02351
02352 *type = base->type;
02353
02354 return CG_OK;
02355 }
02356
02357
02358
02359
02360
02361 int cg_biter_read(int file_number, int B, char *bitername, int *nsteps) {
02362 cgns_biter *biter;
02363
02364 cg = cgi_get_file(file_number);
02365 if (cg == 0) return CG_ERROR;
02366
02367 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
02368
02369 biter = cgi_get_biter(cg, B);
02370 if (biter==0) return CG_NODE_NOT_FOUND;
02371
02372 *nsteps = biter->nsteps;
02373 strcpy(bitername,biter->name);
02374
02375 return CG_OK;
02376 }
02377
02378
02379
02380
02381
02382 int cg_ziter_read(int file_number, int B, int Z, char *zitername) {
02383 cgns_ziter *ziter;
02384
02385 cg = cgi_get_file(file_number);
02386 if (cg == 0) return CG_ERROR;
02387
02388 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
02389
02390 ziter = cgi_get_ziter(cg, B, Z);
02391 if (ziter==0) return CG_NODE_NOT_FOUND;
02392
02393 strcpy(zitername, ziter->name);
02394
02395 return CG_OK;
02396 }
02397
02398
02399
02400
02401
02402 int cg_gravity_read(int file_number, int B, float *gravity_vector) {
02403 cgns_base *base;
02404 cgns_gravity *gravity;
02405
02406
02407 cg = cgi_get_file(file_number);
02408 if (cg == 0) return CG_ERROR;
02409
02410 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
02411
02412
02413 base = cgi_get_base(cg, B);
02414 if (base==0) return CG_ERROR;
02415
02416
02417 gravity = cgi_get_gravity(cg, B);
02418 if (gravity==0) return CG_NODE_NOT_FOUND;
02419
02420 memcpy(gravity_vector, gravity->vector->data, base->phys_dim*sizeof(float));
02421 return CG_OK;
02422 }
02423
02424
02425
02426
02427
02428 int cg_axisym_read(int file_number, int B, float *ref_point, float *axis) {
02429 int n;
02430 cgns_base *base;
02431 cgns_axisym *axisym;
02432
02433
02434 cg = cgi_get_file(file_number);
02435 if (cg == 0) return CG_ERROR;
02436
02437 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
02438
02439
02440 base = cgi_get_base(cg, B);
02441 if (base==0) return CG_ERROR;
02442
02443
02444 axisym = cgi_get_axisym(cg, B);
02445 if (axisym==0) return CG_NODE_NOT_FOUND;
02446
02447 for (n=0; n<axisym->narrays; n++) {
02448 if (strcmp(axisym->array[n].name,"AxisymmetryReferencePoint")==0)
02449 memcpy(ref_point, axisym->array[n].data, base->phys_dim*sizeof(float));
02450 else if (strcmp(axisym->array[n].name,"AxisymmetryAxisVector")==0)
02451 memcpy(axis, axisym->array[n].data, base->phys_dim*sizeof(float));
02452 }
02453 return CG_OK;
02454 }
02455
02456
02457
02458
02459
02460 int cg_bc_wallfunction_read(int file_number, int B, int Z, int BC,
02461 WallFunctionType_t *WallFunctionType) {
02462 cgns_bprop *bprop;
02463
02464
02465 cg = cgi_get_file(file_number);
02466 if (cg == 0) return CG_ERROR;
02467
02468 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
02469
02470
02471 bprop = cgi_get_bprop(cg, B, Z, BC);
02472 if (bprop==0) return CG_NODE_NOT_FOUND;
02473
02474 if (bprop->bcwall==0) {
02475 cgi_error("BCProperty_t/WallFunction_t node doesn't exist under BC_t %d",BC);
02476 return CG_NODE_NOT_FOUND;
02477 }
02478 *WallFunctionType = bprop->bcwall->type;
02479
02480 return CG_OK;
02481 }
02482
02483 int cg_bc_area_read(int file_number, int B, int Z, int BC,
02484 AreaType_t *AreaType, float *SurfaceArea, char *RegionName) {
02485 int n;
02486 cgns_bprop *bprop;
02487
02488
02489 cg = cgi_get_file(file_number);
02490 if (cg == 0) return CG_ERROR;
02491
02492 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
02493
02494
02495 bprop = cgi_get_bprop(cg, B, Z, BC);
02496 if (bprop==0) return CG_NODE_NOT_FOUND;
02497
02498 if (bprop->bcarea==0) {
02499 cgi_error("BCProperty_t/Area_t node doesn't exist under BC_t %d",BC);
02500 return CG_NODE_NOT_FOUND;
02501 }
02502 *AreaType = bprop->bcarea->type;
02503 for (n=0; n<bprop->bcarea->narrays; n++) {
02504 if (strcmp("SurfaceArea",bprop->bcarea->array[n].name)==0)
02505 memcpy(SurfaceArea, bprop->bcarea->array[n].data, sizeof(float));
02506 else if (strcmp("RegionName",bprop->bcarea->array[n].name)==0) {
02507 memcpy(RegionName, bprop->bcarea->array[n].data, 32*sizeof(char));
02508 RegionName[32]='\0';
02509 }
02510 }
02511
02512 return CG_OK;
02513 }
02514
02515
02516
02517
02518
02519 int cg_conn_periodic_read(int file_number, int B, int Z, int I,
02520 float *RotationCenter, float *RotationAngle, float *Translation) {
02521
02522 int n;
02523 cgns_base *base;
02524 cgns_cprop *cprop;
02525 cgns_cperio *cperio;
02526
02527
02528 cg = cgi_get_file(file_number);
02529 if (cg == 0) return CG_ERROR;
02530
02531 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
02532
02533
02534 base = cgi_get_base(cg, B);
02535 if (base==0) return CG_ERROR;
02536
02537
02538 cprop = cgi_get_cprop(cg, B, Z, I);
02539 if (cprop==0) return CG_NODE_NOT_FOUND;
02540
02541 if (cprop->cperio == 0) {
02542 cgi_error("GridConnectivityProperty_t/Periodic_t node doesn't exist under GridConnectivity_t %d",I);
02543 return CG_NODE_NOT_FOUND;
02544 }
02545 cperio = cprop->cperio;
02546
02547
02548 for (n=0; n<cperio->narrays; n++) {
02549 if (strcmp(cperio->array[n].name,"RotationCenter")==0)
02550 memcpy(RotationCenter, cperio->array[n].data, base->phys_dim*sizeof(float));
02551 else if (strcmp(cperio->array[n].name,"RotationAngle")==0)
02552 memcpy(RotationAngle, cperio->array[n].data, base->phys_dim*sizeof(float));
02553 else if (strcmp(cperio->array[n].name,"Translation")==0)
02554 memcpy(Translation, cperio->array[n].data, base->phys_dim*sizeof(float));
02555 }
02556
02557 return CG_OK;
02558 }
02559
02560 int cg_conn_average_read(int file_number, int B, int Z, int I,
02561 AverageInterfaceType_t *AverageInterfaceType) {
02562
02563 cgns_cprop *cprop;
02564
02565
02566 cg = cgi_get_file(file_number);
02567 if (cg == 0) return CG_ERROR;
02568
02569 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
02570
02571
02572 cprop = cgi_get_cprop(cg, B, Z, I);
02573 if (cprop==0) return CG_NODE_NOT_FOUND;
02574
02575 if (cprop->caverage == 0) {
02576 cgi_error("GridConnectivityProperty_t/AverageInterface_t node doesn't exist under GridConnectivity_t %d",I);
02577 return CG_NODE_NOT_FOUND;
02578 }
02579 *AverageInterfaceType = cprop->caverage->type;
02580
02581 return CG_OK;
02582 }
02583
02584 int cg_1to1_periodic_read(int file_number, int B, int Z, int I,
02585 float *RotationCenter, float *RotationAngle, float *Translation)
02586 {
02587 int n;
02588 cgns_base *base;
02589 cgns_cprop *cprop;
02590 cgns_cperio *cperio;
02591 cgns_1to1 *one21;
02592
02593
02594 cg = cgi_get_file(file_number);
02595 if (cg == 0) return CG_ERROR;
02596
02597 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
02598
02599
02600 base = cgi_get_base(cg, B);
02601 if (base==0) return CG_ERROR;
02602
02603
02604 one21 = cgi_get_1to1(cg, B, Z, I);
02605 if (one21==0) return CG_ERROR;
02606
02607 cprop = one21->cprop;
02608
02609 if (cprop == 0 || cprop->cperio == 0) {
02610 cgi_error("GridConnectivityProperty_t/Periodic_t node doesn't exist under GridConnectivity1to1_t %d",I);
02611 return CG_NODE_NOT_FOUND;
02612 }
02613 cperio = cprop->cperio;
02614
02615
02616 for (n=0; n<cperio->narrays; n++) {
02617 if (strcmp(cperio->array[n].name,"RotationCenter")==0)
02618 memcpy(RotationCenter, cperio->array[n].data, base->phys_dim*sizeof(float));
02619 else if (strcmp(cperio->array[n].name,"RotationAngle")==0)
02620 memcpy(RotationAngle, cperio->array[n].data, base->phys_dim*sizeof(float));
02621 else if (strcmp(cperio->array[n].name,"Translation")==0)
02622 memcpy(Translation, cperio->array[n].data, base->phys_dim*sizeof(float));
02623 }
02624
02625 return CG_OK;
02626 }
02627
02628 int cg_1to1_average_read(int file_number, int B, int Z, int I,
02629 AverageInterfaceType_t *AverageInterfaceType)
02630 {
02631 cgns_cprop *cprop;
02632 cgns_1to1 *one21;
02633
02634
02635 cg = cgi_get_file(file_number);
02636 if (cg == 0) return CG_ERROR;
02637
02638 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
02639
02640
02641 one21 = cgi_get_1to1(cg, B, Z, I);
02642 if (one21==0) return CG_ERROR;
02643
02644 cprop = one21->cprop;
02645
02646 if (cprop == 0 || cprop->caverage == 0) {
02647 cgi_error("GridConnectivityProperty_t/AverageInterface_t node doesn't exist under GridConnectivity1to1_t %d",I);
02648 return CG_NODE_NOT_FOUND;
02649 }
02650 *AverageInterfaceType = cprop->caverage->type;
02651
02652 return CG_OK;
02653 }
02654
02655
02656
02657
02658
02659 int cg_goto(int file_number, int B, ...)
02660 {
02661 int n;
02662 va_list ap;
02663 int index[CG_MAX_GOTO_DEPTH];
02664 char *label[CG_MAX_GOTO_DEPTH];
02665
02666
02667 posit = 0;
02668
02669
02670 cg = cgi_get_file(file_number);
02671 if (cg == 0) return CG_ERROR;
02672
02673 va_start(ap, B);
02674
02675
02676 for (n = 0; n < CG_MAX_GOTO_DEPTH; n++) {
02677 label[n] = va_arg(ap,char *);
02678 if (label[n] == NULL || label[n][0] == 0) break;
02679 if (strcmp("end",label[n])==0 || strcmp("END",label[n])==0) break;
02680 index[n] = va_arg(ap, int);
02681 }
02682 va_end(ap);
02683
02684 return cgi_set_posit(file_number, B, n, index, label);
02685 }
02686
02687
02688
02689 int cg_gorel(int file_number, ...)
02690 {
02691 int n = 0;
02692 int index[CG_MAX_GOTO_DEPTH];
02693 char *label[CG_MAX_GOTO_DEPTH];
02694 va_list ap;
02695
02696 if (posit == 0) {
02697 cgi_error ("position not set with cg_goto");
02698 return CG_ERROR;
02699 }
02700 if (file_number != posit_file) {
02701 cgi_error("current position is in the wrong file");
02702 return CG_ERROR;
02703 }
02704
02705 va_start (ap, file_number);
02706 for (n = 0; n < CG_MAX_GOTO_DEPTH; n++) {
02707 label[n] = va_arg(ap, char *);
02708 if (label[n] == NULL || label[n][0] == 0) break;
02709 if (strcmp("end",label[n])==0 || strcmp("END",label[n])==0) break;
02710 index[n] = va_arg(ap, int);
02711 }
02712 va_end(ap);
02713
02714 return cgi_update_posit(n, index, label);
02715 }
02716
02717
02718
02719 int cg_gopath(int file_number, const char *path)
02720 {
02721 int n, len;
02722 const char *p = path, *s;
02723 int index[CG_MAX_GOTO_DEPTH];
02724 char label[CG_MAX_GOTO_DEPTH][33];
02725 char *lab[CG_MAX_GOTO_DEPTH];
02726
02727 if (p == 0 || !*p) {
02728 cgi_error("path not given");
02729 return CG_ERROR;
02730 }
02731
02732
02733
02734 if (*p == '/') {
02735 int ierr, B = 0;
02736
02737 posit = 0;
02738 while (*++p && *p == '/')
02739 ;
02740 if (!*p) {
02741 cgi_error("base name not given");
02742 return CG_ERROR;
02743 }
02744 s = strchr(p, '/');
02745 if (s == 0)
02746 len = strlen(p);
02747 else
02748 len = (int)(s - p);
02749 if (len > 32) {
02750 cgi_error("base name in path is too long");
02751 return CG_ERROR;
02752 }
02753 strncpy(label[0], p, len);
02754 label[0][len] = 0;
02755
02756 cg = cgi_get_file(file_number);
02757 if (cg == 0) return CG_ERROR;
02758
02759 for (n = 0; n < cg->nbases; n++) {
02760 if (0 == strcmp(label[0], cg->base[n].name)) {
02761 B = n + 1;
02762 break;
02763 }
02764 }
02765 if (B == 0) {
02766 cgi_error("base '%s' not found", label[0]);
02767 return CG_ERROR;
02768 }
02769 ierr = cgi_set_posit(file_number, B, 0, index, lab);
02770 if (ierr != CG_OK) return ierr;
02771 if (s == 0) return CG_OK;
02772 p = s;
02773 }
02774
02775
02776
02777 else {
02778 if (posit == 0) {
02779 cgi_error("position not set with cg_goto");
02780 return CG_ERROR;
02781 }
02782 if (file_number != posit_file) {
02783 cgi_error("current position is in the wrong file");
02784 return CG_ERROR;
02785 }
02786 }
02787
02788 n = 0;
02789 while (p && *p) {
02790 while (*p && *p == '/') p++;
02791 if (!*p) break;
02792 s = strchr(p, '/');
02793 if (s == 0)
02794 len = strlen(p);
02795 else
02796 len = (int)(s - p);
02797 if (len > 32) {
02798 posit = 0;
02799 cgi_error("node name in path is too long");
02800 return CG_ERROR;
02801 }
02802 if (n == CG_MAX_GOTO_DEPTH) {
02803 posit = 0;
02804 cgi_error("path is too deep");
02805 return CG_ERROR;
02806 }
02807 strncpy(label[n], p, len);
02808 label[n][len] = 0;
02809 lab[n] = label[n];
02810 index[n++] = 0;
02811 p = s;
02812 }
02813
02814 return cgi_update_posit(n, index, lab);
02815 }
02816
02817
02818
02819 int cg_golist(int file_number, int B, int depth, char **label, int *index)
02820 {
02821 if (depth >= CG_MAX_GOTO_DEPTH) {
02822 cgi_error("path is too deep");
02823 return CG_ERROR;
02824 }
02825 return cgi_set_posit(file_number, B, depth, index, label);
02826 }
02827
02828
02829
02830 int cg_where(int *file_number, int *B, int *depth, char **label, int *num)
02831 {
02832 int n;
02833
02834 if (posit == 0) {
02835 cgi_error ("position not set with cg_goto");
02836 return CG_ERROR;
02837 }
02838 *file_number = posit_file;
02839 *B = posit_base;
02840
02841 *depth = posit_depth > 1 ? posit_depth - 1 : 0;
02842 if (NULL != label) {
02843 for (n = 1; n < posit_depth; n++)
02844 strcpy(label[n], posit_stack[n].label);
02845 }
02846 if (NULL != num) {
02847 for (n = 1; n < posit_depth; n++)
02848 num[n] = posit_stack[n].index;
02849 }
02850 return CG_OK;
02851 }
02852
02853
02854
02855
02856
02857 int cg_famname_read(char *family_name) {
02858 char *famname;
02859 int ier=0;
02860
02861
02862 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
02863
02864 famname = cgi_famname_address(CG_MODE_READ, &ier);
02865 if (famname==0) return ier;
02866
02867 strcpy(family_name,famname);
02868 if (!strlen(famname)) return CG_NODE_NOT_FOUND;
02869 return CG_OK;
02870 }
02871
02872 int cg_convergence_read(int *iterations, char **NormDefinitions) {
02873 cgns_converg *converg;
02874 cgns_descr *descr;
02875 int ier=0;
02876
02877
02878 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
02879
02880 converg = cgi_converg_address(CG_MODE_READ, &ier);
02881 if (converg==0) return ier;
02882
02883 (*iterations) = converg->iterations;
02884 if (converg->NormDefinitions==0) {
02885 NormDefinitions[0] = CGNS_NEW(char, 1);
02886 NormDefinitions[0][0]='\0';
02887 } else {
02888 descr = converg->NormDefinitions;
02889 NormDefinitions[0] = CGNS_NEW(char, strlen(descr->text)+1);
02890 strcpy(NormDefinitions[0], descr->text);
02891 }
02892 return CG_OK;
02893 }
02894
02895 int cg_state_read(char **StateDescription) {
02896 cgns_state *state;
02897 cgns_descr *descr;
02898 int ier=0;
02899
02900
02901 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
02902
02903 state = cgi_state_address(CG_MODE_READ, &ier);
02904 if (state==0) return ier;
02905
02906 if (state->StateDescription == 0) {
02907 StateDescription[0]=CGNS_NEW(char, 1);
02908 StateDescription[0][0]='\0';
02909 } else {
02910 descr = state->StateDescription;
02911 StateDescription[0]=CGNS_NEW(char, strlen(descr->text)+1);
02912 strcpy(StateDescription[0], descr->text);
02913 }
02914 return CG_OK;
02915 }
02916
02917 int cg_equationset_read(int *EquationDimension,
02918 int *GoverningEquationsFlag, int *GasModelFlag,
02919 int *ViscosityModelFlag, int *ThermalConductivityModelFlag,
02920 int *TurbulenceClosureFlag, int *TurbulenceModelFlag) {
02921 cgns_equations *eq;
02922 int ier=0;
02923
02924
02925 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
02926
02927 eq = cgi_equations_address(CG_MODE_READ, &ier);
02928 if (eq==0) return ier;
02929
02930 (*EquationDimension) = eq->equation_dim;
02931 if (eq->governing) (*GoverningEquationsFlag)=1;
02932 else (*GoverningEquationsFlag)=0;
02933
02934 if (eq->gas) (*GasModelFlag)=1;
02935 else (*GasModelFlag)=0;
02936
02937 if (eq->visc) (*ViscosityModelFlag)=1;
02938 else (*ViscosityModelFlag)=0;
02939
02940 if (eq->conduct) (*ThermalConductivityModelFlag)=1;
02941 else (*ThermalConductivityModelFlag)=0;
02942
02943 if (eq->closure) (*TurbulenceClosureFlag)=1;
02944 else (*TurbulenceClosureFlag)=0;
02945
02946 if (eq->turbulence) (*TurbulenceModelFlag)=1;
02947 else (*TurbulenceModelFlag)=0;
02948
02949
02950
02951
02952 return CG_OK;
02953 }
02954
02955 int cg_equationset_chemistry_read(int *ThermalRelaxationFlag,
02956 int *ChemicalKineticsFlag) {
02957 cgns_equations *eq;
02958 int ier=0;
02959
02960
02961 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
02962
02963 eq = cgi_equations_address(CG_MODE_READ, &ier);
02964 if (eq==0) return ier;
02965
02966 if (eq->relaxation) (*ThermalRelaxationFlag)=1;
02967 else (*ThermalRelaxationFlag)=0;
02968
02969 if (eq->chemkin) (*ChemicalKineticsFlag)=1;
02970 else (*ChemicalKineticsFlag)=0;
02971
02972 return CG_OK;
02973 }
02974
02975 int cg_equationset_elecmagn_read(int *ElecFldModelFlag, int *MagnFldModelFlag,
02976 int *ConductivityModelFlag)
02977 {
02978 cgns_equations *eq;
02979 int ier=0;
02980
02981
02982 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
02983
02984 eq = cgi_equations_address(CG_MODE_READ, &ier);
02985 if (eq==0) return ier;
02986
02987 if (eq->elecfield) (*ElecFldModelFlag)=1;
02988 else (*ElecFldModelFlag)=0;
02989
02990 if (eq->magnfield) (*MagnFldModelFlag)=1;
02991 else (*MagnFldModelFlag)=0;
02992
02993 if (eq->emconduct) (*ConductivityModelFlag)=1;
02994 else (*ConductivityModelFlag)=0;
02995
02996 return CG_OK;
02997 }
02998
02999 int cg_governing_read(GoverningEquationsType_t *EquationsType) {
03000 cgns_governing *governing;
03001 int ier=0;
03002
03003
03004 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
03005
03006 governing = cgi_governing_address(CG_MODE_READ, &ier);
03007 if (governing==0) return ier;
03008
03009 (*EquationsType) = governing->type;
03010 return CG_OK;
03011 }
03012
03013 int cg_diffusion_read(int *diffusion_model) {
03014 int n, ndata, ier=0;
03015 int *diffusion, index_dim;
03016
03017
03018 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
03019
03020 diffusion = cgi_diffusion_address(CG_MODE_READ, &ier);
03021 if (diffusion==0) return ier;
03022
03023 if (posit_base && posit_zone) {
03024 index_dim = cg->base[posit_base-1].zone[posit_zone-1].index_dim;
03025
03026
03027 } else if (posit_base) {
03028 index_dim = cg->base[posit_base-1].cell_dim;
03029
03030 } else {
03031 cgi_error("Can't find IndexDimension in cg_diffusion_read.");
03032 return CG_NO_INDEX_DIM;
03033 }
03034 if (index_dim==1) ndata=1;
03035 else if (index_dim==2) ndata=3;
03036 else if (index_dim==3) ndata=6;
03037 else {
03038 cgi_error("invalid value for IndexDimension");
03039 return CG_ERROR;
03040 }
03041
03042 for (n=0; n<ndata; n++) diffusion_model[n] = diffusion[n];
03043
03044 return CG_OK;
03045 }
03046
03047 int cg_model_read(const char *ModelLabel, ModelType_t *ModelType) {
03048 cgns_model *model;
03049 int ier=0;
03050
03051
03052 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
03053
03054 model = cgi_model_address(CG_MODE_READ, ModelLabel, &ier);
03055 if (model==0) return ier;
03056
03057 (*ModelType) = model->type;
03058
03059 return CG_OK;
03060 }
03061
03062 int cg_narrays(int *narrays) {
03063
03064
03065
03066
03067
03068
03069
03070
03071
03072
03073
03074
03075
03076 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
03077
03078
03079 if (posit == 0) {
03080 cgi_error("No current position set by cg_goto\n");
03081 (*narrays) = 0;
03082 return CG_ERROR;
03083 }
03084 if (strcmp(posit->label,"GridCoordinates_t")==0) {
03085 cgns_zcoor *zcoor= (cgns_zcoor *)posit->posit;
03086 (*narrays) = zcoor->ncoords;
03087
03088 } else if (strcmp(posit->label,"FlowSolution_t")==0) {
03089 cgns_sol *sol = (cgns_sol *)posit->posit;
03090 (*narrays) = sol->nfields;
03091
03092 } else if (strcmp(posit->label,"DiscreteData_t")==0) {
03093 cgns_discrete *discrete = (cgns_discrete *)posit->posit;
03094 (*narrays) = discrete->narrays;
03095
03096 } else if (strcmp(posit->label,"GridConnectivity_t")==0) {
03097 cgns_conn *conn = (cgns_conn *)posit->posit;
03098 (*narrays) = conn->narrays;
03099
03100 } else if (strcmp(posit->label,"BC_t")==0) {
03101
03102 (*narrays) = 1;
03103
03104 } else if (strcmp(posit->label,"BCData_t")==0) {
03105 cgns_bcdata *bcdata = (cgns_bcdata *)posit->posit;
03106 (*narrays) = bcdata->narrays;
03107
03108 } else if (strcmp(posit->label,"GasModel_t")==0 ||
03109 strcmp(posit->label,"ViscosityModel_t")==0 ||
03110 strcmp(posit->label,"ThermalConductivityModel_t")==0 ||
03111 strcmp(posit->label,"TurbulenceModel_t")==0 ||
03112 strcmp(posit->label,"TurbulenceClosure_t")==0 ||
03113 strcmp(posit->label,"ThermalRelaxationModel_t")==0 ||
03114 strcmp(posit->label,"ChemicalKineticsModel_t")==0 ||
03115 strcmp(posit->label,"EMElectricFieldModel_t")==0 ||
03116 strcmp(posit->label,"EMMagneticFieldModel_t")==0 ||
03117 strcmp(posit->label,"EMConductivityModel_t")==0) {
03118 cgns_model *model = (cgns_model *)posit->posit;
03119 (*narrays) = model->narrays;
03120
03121 } else if (strcmp(posit->label,"ConvergenceHistory_t")==0) {
03122 cgns_converg *converg = (cgns_converg *)posit->posit;
03123 (*narrays) = converg->narrays;
03124
03125 } else if (strcmp(posit->label,"IntegralData_t")==0) {
03126 cgns_integral *integral = (cgns_integral *)posit->posit;
03127 (*narrays) = integral->narrays;
03128
03129 } else if (strcmp(posit->label,"ReferenceState_t")==0) {
03130 cgns_state *state = (cgns_state *)posit->posit;
03131 (*narrays) = state->narrays;
03132
03133 } else if (strcmp(posit->label,"RigidGridMotion_t")==0) {
03134 cgns_rmotion *rmotion = (cgns_rmotion *)posit->posit;
03135 (*narrays) = rmotion->narrays;
03136
03137 } else if (strcmp(posit->label,"ArbitraryGridMotion_t")==0) {
03138 cgns_amotion *amotion = (cgns_amotion *)posit->posit;
03139 (*narrays) = amotion->narrays;
03140
03141 } else if (strcmp(posit->label,"BaseIterativeData_t")==0) {
03142 cgns_biter *biter = (cgns_biter *)posit->posit;
03143 (*narrays) = biter->narrays;
03144
03145 } else if (strcmp(posit->label,"ZoneIterativeData_t")==0) {
03146 cgns_ziter *ziter = (cgns_ziter *)posit->posit;
03147 (*narrays) = ziter->narrays;
03148
03149 } else if (strcmp(posit->label,"UserDefinedData_t")==0) {
03150 cgns_user_data *user_data = (cgns_user_data *)posit->posit;
03151 (*narrays) = user_data->narrays;
03152
03153 } else if (strcmp(posit->label,"Gravity_t")==0) {
03154 cgns_gravity *gravity = (cgns_gravity *)posit->posit;
03155 (*narrays) = gravity->narrays;
03156
03157 } else if (strcmp(posit->label,"Axisymmetry_t")==0) {
03158 cgns_axisym *axisym = (cgns_axisym *)posit->posit;
03159 (*narrays) = axisym->narrays;
03160
03161 } else if (strcmp(posit->label,"RotatingCoordinates_t")==0) {
03162 cgns_rotating *rotating = (cgns_rotating *)posit->posit;
03163 (*narrays) = rotating->narrays;
03164
03165 } else if (strcmp(posit->label,"Area_t")==0) {
03166 cgns_bcarea *bcarea = (cgns_bcarea *)posit->posit;
03167 (*narrays) = bcarea->narrays;
03168
03169 } else if (strcmp(posit->label,"Periodic_t")==0) {
03170 cgns_cperio *cperio = (cgns_cperio *)posit->posit;
03171 (*narrays) = cperio->narrays;
03172
03173 } else {
03174 cgi_error("User defined DataArray_t node not supported under '%s' type node",posit->label);
03175 (*narrays) = 0;
03176 return CG_INCORRECT_PATH;
03177 }
03178 return CG_OK;
03179 }
03180
03181 int cg_array_info(int A, char *ArrayName, DataType_t *DataType,
03182 int *DataDimension, int *DimensionVector) {
03183
03184 cgns_array *array;
03185 int n, ier=0;
03186
03187
03188 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
03189
03190 array = cgi_array_address(CG_MODE_READ, A, "dummy", &ier);
03191 if (array==0) return ier;
03192
03193 strcpy(ArrayName, array->name);
03194 (*DataType) = cgi_datatype(array->data_type);
03195 (*DataDimension) = array->data_dim;
03196 for (n=0; n<array->data_dim; n++) DimensionVector[n] = array->dim_vals[n];
03197
03198 return CG_OK;
03199 }
03200
03201 int cg_array_read(int A, void *Data) {
03202 cgns_array *array;
03203 int n, num =1, ier=0;
03204
03205
03206 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
03207
03208 array = cgi_array_address(CG_MODE_READ, A, "dummy", &ier);
03209 if (array==0) return ier;
03210
03211 for (n=0; n<array->data_dim; n++) num *= array->dim_vals[n];
03212
03213 if (array->data)
03214 memcpy(Data, array->data, num*size_of(array->data_type));
03215 else {
03216 if (cgio_read_all_data(cg->cgio, array->id, Data)) {
03217 cg_io_error("cgio_read_all_data");
03218 return CG_ERROR;
03219 }
03220 }
03221
03222 return CG_OK;
03223 }
03224
03225 int cg_array_read_as(int A, DataType_t type, void *Data) {
03226 cgns_array *array;
03227 int n, num =1, ier=0;
03228 void *array_data;
03229
03230
03231 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
03232
03233 array = cgi_array_address(CG_MODE_READ, A, "dummy", &ier);
03234 if (array==0) return ier;
03235
03236 for (n=0; n<array->data_dim; n++) num *= array->dim_vals[n];
03237
03238
03239 if ((type==Character && cgi_datatype(array->data_type)!=Character) ||
03240 (type!=Character && cgi_datatype(array->data_type)==Character)) {
03241 cgi_error("Error exit: Character array can only be read as character");
03242 return CG_ERROR;
03243 }
03244 if (type==Character) {
03245 if (array->data)
03246 memcpy(Data, array->data, num*size_of(array->data_type));
03247 else {
03248 if (cgio_read_all_data(cg->cgio, array->id, Data)) {
03249 cg_io_error("cgio_read_all_data");
03250 return CG_ERROR;
03251 }
03252 }
03253 return CG_OK;
03254 }
03255
03256
03257 if (array->data)
03258 array_data = array->data;
03259 else {
03260 array_data = (void *)malloc(num*size_of(array->data_type));
03261 if (array_data == NULL) {
03262 cgi_error("Error allocating array_data");
03263 return CG_ERROR;
03264 }
03265 if (cgio_read_all_data(cg->cgio, array->id, array_data)) {
03266 cg_io_error("cgio_read_all_data");
03267 return CG_ERROR;
03268 }
03269 }
03270
03271
03272
03273 if (type==Integer && cgi_datatype(array->data_type)==Integer) {
03274 for (n=0; n<num; n++) *((int *) Data+n) = *((int *) array_data+n);
03275
03276
03277 } else if (type==Integer && cgi_datatype(array->data_type)==RealSingle) {
03278 for (n=0; n<num; n++) *((int *) Data+n) = (int)(*((float *) array_data+n));
03279
03280
03281 } else if (type==Integer && cgi_datatype(array->data_type)==RealDouble) {
03282 for (n=0; n<num; n++) *((int *) Data+n) = (int)(*((double *) array_data+n));
03283
03284
03285 } else if (type==RealSingle && cgi_datatype(array->data_type)==Integer) {
03286 for (n=0; n<num; n++) *((float *) Data+n) = (float)(*((int *) array_data+n));
03287
03288
03289 } else if (type==RealSingle && cgi_datatype(array->data_type)==RealSingle) {
03290 for (n=0; n<num; n++) *((float *) Data+n) = *((float *) array_data+n);
03291
03292
03293 } else if (type==RealSingle && cgi_datatype(array->data_type)==RealDouble) {
03294 for (n=0; n<num; n++) *((float *) Data+n) = (float)(*((double *) array_data+n));
03295
03296
03297 } else if (type==RealDouble && cgi_datatype(array->data_type)==Integer) {
03298 for (n=0; n<num; n++) *((double *) Data+n) = (double)(*((int *) array_data+n));
03299
03300
03301 } else if (type==RealDouble && cgi_datatype(array->data_type)==RealSingle) {
03302 for (n=0; n<num; n++) *((double *) Data+n) = (double)(*((float *) array_data+n));
03303
03304
03305 } else if (type==RealDouble && cgi_datatype(array->data_type)==RealDouble) {
03306 for (n=0; n<num; n++) *((double *) Data+n) = *((double *) array_data+n);
03307 }
03308
03309 if (array_data != array->data) free(array_data);
03310
03311 return CG_OK;
03312 }
03313
03314 int cg_nintegrals(int *nintegrals) {
03315
03316
03317 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
03318
03319
03320 if (posit == 0) {
03321 cgi_error("No current position set by cg_goto\n");
03322 (*nintegrals) = 0;
03323 return CG_ERROR;
03324 }
03325
03326 if (strcmp(posit->label,"CGNSBase_t")==0) {
03327 cgns_base *base= (cgns_base *)posit->posit;
03328 (*nintegrals) = base->nintegrals;
03329
03330 } else if (strcmp(posit->label,"Zone_t")==0) {
03331 cgns_zone *zone = (cgns_zone *)posit->posit;
03332 (*nintegrals) = zone->nintegrals;
03333 } else {
03334 cgi_error("IntegralData_t node not supported under '%s' type node",posit->label);
03335 (*nintegrals) = 0;
03336 return CG_INCORRECT_PATH;
03337 }
03338 return CG_OK;
03339 }
03340
03341 int cg_integral_read(int IntegralDataIndex, char *IntegralDataName) {
03342 int ier=0;
03343 cgns_integral *integral;
03344
03345
03346 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
03347
03348 integral = cgi_integral_address(CG_MODE_READ, IntegralDataIndex,
03349 "dummy", &ier);
03350 if (integral==0) return ier;
03351
03352 strcpy(IntegralDataName, integral->name);
03353 return CG_OK;
03354 }
03355
03356 int cg_rind_read(int *RindData) {
03357 int n, ier=0;
03358 int *rind, index_dim;
03359
03360
03361 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
03362
03363 rind = cgi_rind_address(CG_MODE_READ, &ier);
03364 if (rind==0) return ier;
03365
03366 if (posit_base && posit_zone) {
03367 index_dim = cg->base[posit_base-1].zone[posit_zone-1].index_dim;
03368 } else {
03369 cgi_error("Can't find IndexDimension in cg_rind_read.");
03370 return CG_NO_INDEX_DIM;
03371 }
03372
03373 for (n=0; n<2*index_dim; n++) RindData[n] = rind[n];
03374 return CG_OK;
03375 }
03376
03377 int cg_ndescriptors(int *ndescriptors) {
03378
03379
03380
03381
03382
03383
03384
03385
03386
03387
03388
03389
03390
03391
03392
03393
03394
03395
03396 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
03397
03398
03399 if (posit == 0) {
03400 cgi_error("No current position set by cg_goto\n");
03401 (*ndescriptors)=0;
03402 return CG_ERROR;
03403 }
03404
03405 if (strcmp(posit->label,"CGNSBase_t")==0)
03406 NDESCRIPTOR(cgns_base)
03407 else if (strcmp(posit->label,"Zone_t")==0)
03408 NDESCRIPTOR(cgns_zone)
03409 else if (strcmp(posit->label,"GridCoordinates_t")==0)
03410 NDESCRIPTOR(cgns_zcoor)
03411 else if (strcmp(posit->label,"Elements_t")==0)
03412 NDESCRIPTOR(cgns_section)
03413 else if (strcmp(posit->label,"FlowSolution_t")==0)
03414 NDESCRIPTOR(cgns_sol)
03415 else if (strcmp(posit->label,"DiscreteData_t")==0)
03416 NDESCRIPTOR(cgns_discrete)
03417 else if (strcmp(posit->label,"ZoneGridConnectivity_t")==0)
03418 NDESCRIPTOR(cgns_zconn)
03419 else if (strcmp(posit->label,"GridConnectivity1to1_t")==0)
03420 NDESCRIPTOR(cgns_1to1)
03421 else if (strcmp(posit->label,"GridConnectivity_t")==0)
03422 NDESCRIPTOR(cgns_conn)
03423 else if (strcmp(posit->label,"OversetHoles_t")==0)
03424 NDESCRIPTOR(cgns_hole)
03425 else if (strcmp(posit->label,"ZoneBC_t")==0)
03426 NDESCRIPTOR(cgns_zboco)
03427 else if (strcmp(posit->label,"BC_t")==0)
03428 NDESCRIPTOR(cgns_boco)
03429 else if (strcmp(posit->label,"BCDataSet_t")==0)
03430 NDESCRIPTOR(cgns_dataset)
03431 else if (strcmp(posit->label,"BCData_t")==0)
03432 NDESCRIPTOR(cgns_bcdata)
03433 else if (strcmp(posit->label,"FlowEquationSet_t")==0)
03434 NDESCRIPTOR(cgns_equations)
03435 else if (strcmp(posit->label,"GoverningEquations_t")==0)
03436 NDESCRIPTOR(cgns_governing)
03437 else if (strcmp(posit->label,"GasModel_t")==0 ||
03438 strcmp(posit->label,"ViscosityModel_t")==0 ||
03439 strcmp(posit->label,"ThermalConductivityModel_t")==0 ||
03440 strcmp(posit->label,"TurbulenceModel_t")==0 ||
03441 strcmp(posit->label,"TurbulenceClosure_t")==0 ||
03442 strcmp(posit->label,"ThermalRelaxationModel_t")==0 ||
03443 strcmp(posit->label,"ChemicalKineticsModel_t")==0 ||
03444 strcmp(posit->label,"EMElectricFieldModel_t")==0 ||
03445 strcmp(posit->label,"EMMagneticFieldModel_t")==0 ||
03446 strcmp(posit->label,"EMConductivityModel_t")==0)
03447 NDESCRIPTOR(cgns_model)
03448 else if (strcmp(posit->label,"ConvergenceHistory_t")==0)
03449 NDESCRIPTOR(cgns_converg)
03450 else if (strcmp(posit->label,"IntegralData_t")==0)
03451 NDESCRIPTOR(cgns_integral)
03452 else if (strcmp(posit->label,"ReferenceState_t")==0)
03453 NDESCRIPTOR(cgns_state)
03454 else if (strcmp(posit->label,"DataArray_t")==0)
03455 NDESCRIPTOR(cgns_array)
03456 else if (strcmp(posit->label,"Family_t")==0)
03457 NDESCRIPTOR(cgns_family)
03458 else if (strcmp(posit->label,"GeometryReference_t")==0)
03459 NDESCRIPTOR(cgns_geo)
03460 else if (strcmp(posit->label,"RigidGridMotion_t")==0)
03461 NDESCRIPTOR(cgns_rmotion)
03462 else if (strcmp(posit->label,"ArbitraryGridMotion_t")==0)
03463 NDESCRIPTOR(cgns_amotion)
03464 else if (strcmp(posit->label,"BaseIterativeData_t")==0)
03465 NDESCRIPTOR(cgns_biter)
03466 else if (strcmp(posit->label,"ZoneIterativeData_t")==0)
03467 NDESCRIPTOR(cgns_ziter)
03468 else if (strcmp(posit->label,"UserDefinedData_t")==0)
03469 NDESCRIPTOR(cgns_user_data)
03470 else if (strcmp(posit->label,"Gravity_t")==0)
03471 NDESCRIPTOR(cgns_gravity)
03472 else if (strcmp(posit->label,"Axisymmetry_t")==0)
03473 NDESCRIPTOR(cgns_axisym)
03474 else if (strcmp(posit->label,"RotatingCoordinates_t")==0)
03475 NDESCRIPTOR(cgns_rotating)
03476 else if (strcmp(posit->label,"BCProperty_t")==0)
03477 NDESCRIPTOR(cgns_bprop)
03478 else if (strcmp(posit->label,"WallFunction_t")==0)
03479 NDESCRIPTOR(cgns_bcwall)
03480 else if (strcmp(posit->label,"Area_t")==0)
03481 NDESCRIPTOR(cgns_bcarea)
03482 else if (strcmp(posit->label,"GridConnectivityProperty_t")==0)
03483 NDESCRIPTOR(cgns_cprop)
03484 else if (strcmp(posit->label,"Periodic_t")==0)
03485 NDESCRIPTOR(cgns_cperio)
03486 else if (strcmp(posit->label,"AverageInterface_t")==0)
03487 NDESCRIPTOR(cgns_caverage)
03488 else {
03489 cgi_error("Descriptor_t node not supported under '%s' type node",posit->label);
03490 (*ndescriptors)=0;
03491 return CG_INCORRECT_PATH;
03492 }
03493 return CG_OK;
03494 }
03495
03496 int cg_descriptor_read(int descr_no, char *descr_name, char **descr_text) {
03497 cgns_descr *descr;
03498 int ier=0;
03499
03500
03501 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
03502
03503
03504 descr = cgi_descr_address(CG_MODE_READ, descr_no, "dummy", &ier);
03505 if (descr==0) return ier;
03506
03507
03508 descr_text[0]=CGNS_NEW(char, strlen(descr->text)+1);
03509 strcpy(descr_text[0], descr->text);
03510 strcpy(descr_name, descr->name);
03511
03512 return CG_OK;
03513 }
03514
03515 int cg_nunits(int *nunits) {
03516 cgns_units *units;
03517 int ier=0;
03518
03519 *nunits = 0;
03520
03521 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
03522
03523 units = cgi_units_address(CG_MODE_READ, &ier);
03524 if (units==0) return ier;
03525 *nunits = units->nunits;
03526 return CG_OK;
03527 }
03528
03529 int cg_units_read(MassUnits_t *mass, LengthUnits_t *length, TimeUnits_t *time,
03530 TemperatureUnits_t *temperature, AngleUnits_t *angle) {
03531
03532 cgns_units *units;
03533 int ier=0;
03534
03535
03536 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
03537
03538 units = cgi_units_address(CG_MODE_READ, &ier);
03539 if (units==0) return ier;
03540
03541 (*mass) = units->mass;
03542 (*length) = units->length;
03543 (*time) = units->time;
03544 (*temperature) = units->temperature;
03545 (*angle) = units->angle;
03546 return CG_OK;
03547 }
03548
03549 int cg_unitsfull_read(MassUnits_t *mass, LengthUnits_t *length,
03550 TimeUnits_t *time, TemperatureUnits_t *temperature, AngleUnits_t *angle,
03551 ElectricCurrentUnits_t *current, SubstanceAmountUnits_t *amount,
03552 LuminousIntensityUnits_t *intensity) {
03553
03554 cgns_units *units;
03555 int ier=0;
03556
03557
03558 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
03559
03560 units = cgi_units_address(CG_MODE_READ, &ier);
03561 if (units==0) return ier;
03562
03563 (*mass) = units->mass;
03564 (*length) = units->length;
03565 (*time) = units->time;
03566 (*temperature) = units->temperature;
03567 (*angle) = units->angle;
03568 (*current) = units->current;
03569 (*amount) = units->amount;
03570 (*intensity) = units->intensity;
03571 return CG_OK;
03572 }
03573
03574 int cg_exponents_info(DataType_t *DataType) {
03575 cgns_exponent *exponent;
03576 int ier=0;
03577
03578
03579 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
03580
03581 exponent = cgi_exponent_address(CG_MODE_READ, &ier);
03582 if (exponent==0) return ier;
03583
03584 (*DataType) = cgi_datatype(exponent->data_type);
03585 return CG_OK;
03586 }
03587
03588 int cg_nexponents(int *numexp) {
03589 cgns_exponent *exponent;
03590 int ier=0;
03591
03592 *numexp = 0;
03593
03594 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
03595
03596 exponent = cgi_exponent_address(CG_MODE_READ, &ier);
03597 if (exponent==0) return ier;
03598 *numexp = exponent->nexps;
03599 return CG_OK;
03600 }
03601
03602 int cg_exponents_read(void *exponents) {
03603 cgns_exponent *exponent;
03604 int ier=0;
03605
03606
03607 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
03608
03609 exponent = cgi_exponent_address(CG_MODE_READ, &ier);
03610 if (exponent==0) return ier;
03611
03612 if (cgi_datatype(exponent->data_type)==RealSingle) {
03613 (*((float *)exponents+0)) = (*((float *) exponent->data+0));
03614 (*((float *)exponents+1)) = (*((float *) exponent->data+1));
03615 (*((float *)exponents+2)) = (*((float *) exponent->data+2));
03616 (*((float *)exponents+3)) = (*((float *) exponent->data+3));
03617 (*((float *)exponents+4)) = (*((float *) exponent->data+4));
03618
03619 } else if (cgi_datatype(exponent->data_type)==RealDouble) {
03620 (*((double *)exponents+0)) = (*((double *) exponent->data+0));
03621 (*((double *)exponents+1)) = (*((double *) exponent->data+1));
03622 (*((double *)exponents+2)) = (*((double *) exponent->data+2));
03623 (*((double *)exponents+3)) = (*((double *) exponent->data+3));
03624 (*((double *)exponents+4)) = (*((double *) exponent->data+4));
03625 }
03626 return CG_OK;
03627 }
03628
03629 int cg_expfull_read(void *exponents)
03630 {
03631 cgns_exponent *exponent;
03632 int ier=0;
03633
03634
03635 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
03636
03637 exponent = cgi_exponent_address(CG_MODE_READ, &ier);
03638 if (exponent==0) return ier;
03639
03640
03641
03642
03643
03644
03645
03646
03647 if (cgi_datatype(exponent->data_type)==RealSingle) {
03648 (*((float *)exponents+0)) = (*((float *) exponent->data+0));
03649 (*((float *)exponents+1)) = (*((float *) exponent->data+1));
03650 (*((float *)exponents+2)) = (*((float *) exponent->data+2));
03651 (*((float *)exponents+3)) = (*((float *) exponent->data+3));
03652 (*((float *)exponents+4)) = (*((float *) exponent->data+4));
03653 if (exponent->nexps == 8) {
03654 (*((float *)exponents+5)) = (*((float *) exponent->data+5));
03655 (*((float *)exponents+6)) = (*((float *) exponent->data+6));
03656 (*((float *)exponents+7)) = (*((float *) exponent->data+7));
03657 }
03658 else {
03659 (*((float *)exponents+5)) = (float)0.0;
03660 (*((float *)exponents+6)) = (float)0.0;;
03661 (*((float *)exponents+7)) = (float)0.0;;
03662 }
03663
03664 } else if (cgi_datatype(exponent->data_type)==RealDouble) {
03665 (*((double *)exponents+0)) = (*((double *) exponent->data+0));
03666 (*((double *)exponents+1)) = (*((double *) exponent->data+1));
03667 (*((double *)exponents+2)) = (*((double *) exponent->data+2));
03668 (*((double *)exponents+3)) = (*((double *) exponent->data+3));
03669 (*((double *)exponents+4)) = (*((double *) exponent->data+4));
03670 if (exponent->nexps == 8) {
03671 (*((double *)exponents+5)) = (*((double *) exponent->data+5));
03672 (*((double *)exponents+6)) = (*((double *) exponent->data+6));
03673 (*((double *)exponents+7)) = (*((double *) exponent->data+7));
03674 }
03675 else {
03676 (*((double *)exponents+5)) = (double)0.0;
03677 (*((double *)exponents+6)) = (double)0.0;;
03678 (*((double *)exponents+7)) = (double)0.0;;
03679 }
03680 }
03681 return CG_OK;
03682 }
03683
03684 int cg_conversion_info(DataType_t *DataType) {
03685 cgns_conversion *conversion;
03686 int ier=0;
03687
03688
03689 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
03690
03691 conversion = cgi_conversion_address(CG_MODE_READ, &ier);
03692 if (conversion==0) return ier;
03693
03694 (*DataType) = cgi_datatype(conversion->data_type);
03695 return CG_OK;
03696 }
03697
03698 int cg_conversion_read(void *ConversionFactors) {
03699 cgns_conversion *conversion;
03700 int ier=0;
03701
03702
03703 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
03704
03705 conversion = cgi_conversion_address(CG_MODE_READ, &ier);
03706 if (conversion==0) return ier;
03707
03708 if (cgi_datatype(conversion->data_type)==RealSingle) {
03709 *((float *)ConversionFactors+0) = *((float *) conversion->data+0);
03710 *((float *)ConversionFactors+1) = *((float *) conversion->data+1);
03711
03712 } else if (cgi_datatype(conversion->data_type)==RealDouble) {
03713 *((double *)ConversionFactors+0) = *((double *) conversion->data+0);
03714 *((double *)ConversionFactors+1) = *((double *) conversion->data+1);
03715 }
03716 return CG_OK;
03717 }
03718
03719 int cg_dataclass_read(DataClass_t *dataclass) {
03720 DataClass_t *DataClass;
03721 int ier=0;
03722
03723
03724 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
03725
03726 DataClass = cgi_dataclass_address(CG_MODE_READ, &ier);
03727 if (DataClass==0) return ier;
03728
03729 if (*DataClass==DataClassNull) return CG_NODE_NOT_FOUND;
03730 (*dataclass) = (*DataClass);
03731 return CG_OK;
03732 }
03733
03734 int cg_gridlocation_read(GridLocation_t *GridLocation) {
03735 GridLocation_t *location;
03736 int ier=0;
03737
03738
03739 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
03740
03741 location = cgi_location_address(CG_MODE_READ, &ier);
03742 if (location==0) return ier;
03743
03744 (*GridLocation) = (*location);
03745 return CG_OK;
03746 }
03747
03748 int cg_ordinal_read(int *Ordinal) {
03749 int *ordinal;
03750 int ier=0;
03751
03752
03753 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
03754
03755 ordinal = cgi_ordinal_address(CG_MODE_READ, &ier);
03756 if (ordinal==0) return ier;
03757
03758 (*Ordinal) = (*ordinal);
03759 return CG_OK;
03760 }
03761
03762 int cg_is_link(int *path_length) {
03763 double posit_id;
03764
03765 *path_length = 0;
03766
03767
03768 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ))
03769 return CG_ERROR;
03770
03771 if (cgi_posit_id(&posit_id)) return CG_ERROR;
03772
03773 if (cgio_is_link(cg->cgio, posit_id, path_length)) {
03774 cg_io_error("cgio_is_link");
03775 return CG_ERROR;
03776 }
03777
03778 return CG_OK;
03779 }
03780
03781 int cg_link_read(char **filename, char **link_path) {
03782 int name_len, file_len;
03783 double posit_id;
03784
03785
03786 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
03787
03788 if (cgi_posit_id(&posit_id)) return CG_ERROR;
03789
03790 if (cgio_link_size(cg->cgio, posit_id, &file_len, &name_len)) {
03791 cg_io_error("cgio_link_size");
03792 return CG_ERROR;
03793 }
03794 *filename = CGNS_NEW(char, file_len + 1);
03795 *link_path = CGNS_NEW(char, name_len + 1);
03796
03797 if (cgio_get_link(cg->cgio, posit_id, *link_path, *filename)) {
03798 CGNS_FREE(*filename);
03799 CGNS_FREE(*link_path);
03800 *filename = *link_path = 0;
03801 cg_io_error("cgio_get_link");
03802 return CG_ERROR;
03803 }
03804 return CG_OK;
03805 }
03806
03807 int cg_nuser_data(int *nuser_data) {
03808
03809
03810
03811
03812
03813
03814
03815
03816
03817
03818
03819
03820
03821
03822
03823
03824 if (posit == 0) {
03825 cgi_error("No current position set by cg_goto\n");
03826 (*nuser_data) = 0;
03827 return CG_ERROR;
03828 }
03829
03830 if (strcmp(posit->label,"IntegralData_t")==0)
03831 (*nuser_data) = ((cgns_integral *)posit->posit)->nuser_data;
03832 else if (strcmp(posit->label,"DiscreteData_t")==0)
03833 (*nuser_data) = ((cgns_discrete *)posit->posit)->nuser_data;
03834 else if (strcmp(posit->label,"ConvergenceHistory_t")==0)
03835 (*nuser_data) = ((cgns_converg *)posit->posit)->nuser_data;
03836 else if (strcmp(posit->label,"ReferenceState_t")==0)
03837 (*nuser_data) = ((cgns_state *)posit->posit)->nuser_data;
03838 else if ( (strcmp(posit->label,"GasModel_t")==0 ||
03839 strcmp(posit->label,"ViscosityModel_t")==0 ||
03840 strcmp(posit->label,"ThermalConductivityModel_t")==0 ||
03841 strcmp(posit->label,"TurbulenceModel_t")==0 ||
03842 strcmp(posit->label,"TurbulenceClosure_t")==0 ||
03843 strcmp(posit->label,"ThermalRelaxationModel_t")==0 ||
03844 strcmp(posit->label,"ChemicalKineticsModel_t")==0 ||
03845 strcmp(posit->label,"EMElectricFieldModel_t")==0 ||
03846 strcmp(posit->label,"EMMagneticFieldModel_t")==0 ||
03847 strcmp(posit->label,"EMConductivityModel_t")==0) )
03848 (*nuser_data) = ((cgns_model *)posit->posit)->nuser_data;
03849 else if (strcmp(posit->label,"GoverningEquations_t")==0)
03850 (*nuser_data) = ((cgns_governing *)posit->posit)->nuser_data;
03851 else if (strcmp(posit->label,"FlowEquationSet_t")==0)
03852 (*nuser_data) = ((cgns_equations *)posit->posit)->nuser_data;
03853 else if (strcmp(posit->label,"BCData_t")==0)
03854 (*nuser_data) = ((cgns_bcdata *)posit->posit)->nuser_data;
03855 else if (strcmp(posit->label,"BCDataSet_t")==0)
03856 (*nuser_data) = ((cgns_dataset *)posit->posit)->nuser_data;
03857 else if (strcmp(posit->label,"Elements_t")==0)
03858 (*nuser_data) = ((cgns_section *)posit->posit)->nuser_data;
03859 else if (strcmp(posit->label,"BC_t")==0)
03860 (*nuser_data) = ((cgns_boco *)posit->posit)->nuser_data;
03861 else if (strcmp(posit->label,"ZoneBC_t")==0)
03862 (*nuser_data) = ((cgns_zboco *)posit->posit)->nuser_data;
03863 else if (strcmp(posit->label,"OversetHoles_t")==0)
03864 (*nuser_data) = ((cgns_hole *)posit->posit)->nuser_data;
03865 else if (strcmp(posit->label,"GridConnectivity_t")==0)
03866 (*nuser_data) = ((cgns_conn *)posit->posit)->nuser_data;
03867 else if (strcmp(posit->label,"GridConnectivity1to1_t")==0)
03868 (*nuser_data) = ((cgns_1to1 *)posit->posit)->nuser_data;
03869 else if (strcmp(posit->label,"ZoneGridConnectivity_t")==0)
03870 (*nuser_data) = ((cgns_zconn *)posit->posit)->nuser_data;
03871 else if (strcmp(posit->label,"FlowSolution_t")==0)
03872 (*nuser_data) = ((cgns_sol *)posit->posit)->nuser_data;
03873 else if (strcmp(posit->label,"GridCoordinates_t")==0)
03874 (*nuser_data) = ((cgns_zcoor *)posit->posit)->nuser_data;
03875 else if (strcmp(posit->label,"RigidGridMotion_t")==0)
03876 (*nuser_data) = ((cgns_rmotion *)posit->posit)->nuser_data;
03877 else if (strcmp(posit->label,"ArbitraryGridMotion_t")==0)
03878 (*nuser_data) = ((cgns_amotion *)posit->posit)->nuser_data;
03879 else if (strcmp(posit->label,"ZoneIterativeData_t")==0)
03880 (*nuser_data) = ((cgns_ziter *)posit->posit)->nuser_data;
03881 else if (strcmp(posit->label,"BaseIterativeData_t")==0)
03882 (*nuser_data) = ((cgns_biter *)posit->posit)->nuser_data;
03883 else if (strcmp(posit->label,"Zone_t")==0)
03884 (*nuser_data) = ((cgns_zone *)posit->posit)->nuser_data;
03885 else if (strcmp(posit->label,"GeometryReference_t")==0)
03886 (*nuser_data) = ((cgns_geo *)posit->posit)->nuser_data;
03887 else if (strcmp(posit->label,"Family_t")==0)
03888 (*nuser_data) = ((cgns_family *)posit->posit)->nuser_data;
03889 else if (strcmp(posit->label,"CGNSBase_t")==0)
03890 (*nuser_data) = ((cgns_base *)posit->posit)->nuser_data;
03891 else if (strcmp(posit->label,"Gravity_t")==0)
03892 (*nuser_data) = ((cgns_gravity *)posit->posit)->nuser_data;
03893 else if (strcmp(posit->label,"Axisymmetry_t")==0)
03894 (*nuser_data) = ((cgns_axisym *)posit->posit)->nuser_data;
03895 else if (strcmp(posit->label,"RotatingCoordinates_t")==0)
03896 (*nuser_data) = ((cgns_rotating *)posit->posit)->nuser_data;
03897 else if (strcmp(posit->label,"BCProperty_t")==0)
03898 (*nuser_data) = ((cgns_bprop *)posit->posit)->nuser_data;
03899 else if (strcmp(posit->label,"WallFunction_t")==0)
03900 (*nuser_data) = ((cgns_bcwall *)posit->posit)->nuser_data;
03901 else if (strcmp(posit->label,"Area_t")==0)
03902 (*nuser_data) = ((cgns_bcarea *)posit->posit)->nuser_data;
03903 else if (strcmp(posit->label,"UserDefinedData_t")==0)
03904 (*nuser_data) = ((cgns_user_data *)posit->posit)->nuser_data;
03905 else if (strcmp(posit->label,"GridConnectivityProperty_t")==0)
03906 (*nuser_data) = ((cgns_cprop *)posit->posit)->nuser_data;
03907 else if (strcmp(posit->label,"Periodic_t")==0)
03908 (*nuser_data) = ((cgns_cperio *)posit->posit)->nuser_data;
03909 else if (strcmp(posit->label,"AverageInterface_t")==0)
03910 (*nuser_data) = ((cgns_caverage *)posit->posit)->nuser_data;
03911
03912 else {
03913 cgi_error("UserDefinedData_t node not supported under '%s' type node",posit->label);
03914 (*nuser_data) = 0;
03915 return CG_INCORRECT_PATH;
03916 }
03917 return CG_OK;
03918 }
03919
03920 int cg_user_data_read(int Index, char *UserDataName) {
03921 int ier=0;
03922 cgns_user_data *user_data;
03923
03924
03925 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
03926
03927 user_data = cgi_user_data_address(CG_MODE_READ, Index,
03928 "dummy", &ier);
03929 if (user_data==0) return ier;
03930
03931 strcpy(UserDataName, user_data->name);
03932 return CG_OK;
03933 }
03934
03935 int cg_rotating_read(float *rot_rate, float *rot_center) {
03936 cgns_rotating *rotating;
03937 cgns_base *base;
03938 int ier=0, n;
03939
03940
03941 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
03942
03943 rotating = cgi_rotating_address(CG_MODE_READ, &ier);
03944 if (rotating==0) return ier;
03945
03946 if (posit_base) {
03947 base = &cg->base[posit_base-1];
03948 } else {
03949 cgi_error("Can't find the base");
03950 return CG_ERROR;
03951 }
03952
03953 for (n=0; n<rotating->narrays; n++) {
03954 if (strcmp(rotating->array[n].name,"RotationCenter")==0)
03955 memcpy(rot_center, rotating->array[n].data, base->phys_dim*sizeof(float));
03956 else if (strcmp(rotating->array[n].name,"RotationRateVector")==0)
03957 memcpy(rot_rate, rotating->array[n].data, base->phys_dim*sizeof(float));
03958 }
03959 return CG_OK;
03960 }
03961
03962 int cg_ptset_info(PointSetType_t *ptset_type, int *npnts)
03963 {
03964 cgns_ptset *ptset;
03965 int ier=0;
03966
03967 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ))
03968 return CG_ERROR;
03969
03970 ptset = cgi_ptset_address(CG_MODE_READ, &ier);
03971 if (ptset == 0)
03972 return ier;
03973
03974 *ptset_type = ptset->type;
03975 *npnts = ptset->npts;
03976
03977 return CG_OK;
03978 }
03979
03980 int cg_ptset_read(int *pnts)
03981 {
03982 cgns_ptset *ptset;
03983 int ier=0;
03984
03985 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
03986
03987 ptset = cgi_ptset_address(CG_MODE_READ, &ier);
03988 if (ptset == 0)
03989 return ier;
03990
03991
03992 if (ptset->npts > 0) {
03993 if (cgio_read_all_data(cg->cgio, ptset->id, (void *)pnts)) {
03994 cg_io_error("cgio_read_all_data");
03995 return CG_ERROR;
03996 }
03997
03998
03999
04000
04001
04002 }
04003
04004 return CG_OK;
04005 }
04006
04007
04008
04009
04010 int cg_base_write(int file_number, char const * basename, int cell_dim, int phys_dim, int *B) {
04011 cgns_base *base = NULL;
04012 int index;
04013 int dim_vals;
04014 int data[2];
04015
04016
04017 if (cgi_check_strlen(basename)) return CG_ERROR;
04018 if (cell_dim<1 || cell_dim>3 || phys_dim<1 || phys_dim>3) {
04019 cgi_error("Invalid input: cell_dim=%d, phys_dim=%d",cell_dim,phys_dim);
04020 return CG_ERROR;
04021 }
04022
04023 cg = cgi_get_file(file_number);
04024 if (cg == 0) return CG_ERROR;
04025
04026 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
04027
04028
04029 for (index=0; index<cg->nbases; index++) {
04030 if (strcmp(basename, cg->base[index].name)==0) {
04031
04032
04033 if (cg->mode==CG_MODE_WRITE) {
04034 cgi_error("Duplicate child name found: %s",basename);
04035 return CG_ERROR;
04036 }
04037
04038
04039
04040 if (cgi_delete_node(cg->rootid, cg->base[index].id))
04041 return CG_ERROR;
04042
04043 base = &(cg->base[index]);
04044
04045 cgi_free_base(base);
04046 break;
04047 }
04048 }
04049
04050 if (index==cg->nbases) {
04051 if (cg->nbases == 0) {
04052 cg->base = CGNS_NEW(cgns_base, cg->nbases+1);
04053 } else {
04054 cg->base = CGNS_RENEW(cgns_base, cg->nbases+1, cg->base);
04055 }
04056 base = &(cg->base[cg->nbases]);
04057 cg->nbases ++;
04058 }
04059 (*B) = index+1;
04060
04061
04062 strcpy(base->name, basename);
04063 base->cell_dim = cell_dim;
04064 base->phys_dim = phys_dim;
04065 base->id=0;
04066 base->nzones=0;
04067 base->ndescr=0;
04068 base->nfamilies=0;
04069 base->state=0;
04070 base->data_class=DataClassNull;
04071 base->units=0;
04072 base->equations=0;
04073 base->converg=0;
04074 base->nintegrals=0;
04075 base->biter=0;
04076 base->type=SimulationTypeNull;
04077 base->type_id=0;
04078 base->nuser_data=0;
04079 base->gravity=0;
04080 base->axisym=0;
04081 base->rotating=0;
04082
04083
04084 data[0] = cell_dim;
04085 data[1] = phys_dim;
04086 dim_vals=2;
04087 if (cgi_new_node(cg->rootid, base->name, "CGNSBase_t", &base->id,
04088 "I4", 1, &dim_vals, (void *)data)) return CG_ERROR;
04089
04090 return CG_OK;
04091 }
04092
04093 int cg_zone_write(int file_number, int B, char const *zonename, int const * nijk,
04094 ZoneType_t type, int *Z) {
04095 cgns_base *base;
04096 cgns_zone *zone = NULL;
04097 int index, i, index_dim;
04098 int dim_vals[2];
04099 double dummy_id;
04100
04101
04102 if (cgi_check_strlen(zonename)) return CG_ERROR;
04103
04104
04105 cg = cgi_get_file(file_number);
04106 if (cg == 0) return CG_ERROR;
04107
04108
04109 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
04110
04111
04112 base = cgi_get_base(cg, B);
04113 if (base==0) return CG_ERROR;
04114
04115
04116 if (type == Structured)
04117 index_dim = base->cell_dim;
04118 else if (type == Unstructured)
04119 index_dim = 1;
04120 else {
04121 cgi_error("Invalid zone type - not Structured or Unstructured");
04122 return CG_ERROR;
04123 }
04124
04125 for (i=0; i<index_dim; i++) {
04126 if (nijk[i]<=0) {
04127 cgi_error("Invalid input: nijk[%d]=%d", i, nijk[i]);
04128 return CG_ERROR;
04129 }
04130 if (type == Structured && nijk[i]!=nijk[i+index_dim]+1) {
04131 cgi_error("Invalid input: VertexSize[%d]=%d and CellSize[%d]=%d",
04132 i, nijk[i], i, nijk[i+index_dim]);
04133 return CG_ERROR;
04134 }
04135 }
04136
04137
04138 for (index=0; index<base->nzones; index++) {
04139 if (strcmp(zonename, base->zone[index].name)==0) {
04140
04141
04142 if (cg->mode==CG_MODE_WRITE) {
04143 cgi_error("Duplicate child name found: %s",zonename);
04144 return CG_ERROR;
04145 }
04146
04147
04148
04149 if (cgi_delete_node(base->id, base->zone[index].id))
04150 return CG_ERROR;
04151
04152 zone = &(base->zone[index]);
04153
04154 cgi_free_zone(zone);
04155 break;
04156 }
04157 }
04158
04159 if (index==base->nzones) {
04160 if (base->nzones == 0) {
04161 base->zone = CGNS_NEW(cgns_zone, base->nzones+1);
04162 } else {
04163 base->zone = CGNS_RENEW(cgns_zone, base->nzones+1, base->zone);
04164 }
04165 zone = &(base->zone[base->nzones]);
04166 base->nzones++;
04167 }
04168 (*Z) = index+1;
04169
04170
04171 strcpy(zone->name,zonename);
04172 if ((zone->nijk = (int *)malloc(index_dim*3*sizeof(int)))==NULL) {
04173 cgi_error("Error allocating zone->nijk");
04174 return CG_ERROR;
04175 }
04176 for (i=0; i<3*index_dim; i++) zone->nijk[i] = nijk[i];
04177 zone->index_dim = index_dim;
04178 zone->type = type;
04179
04180
04181
04182 zone->id = 0;
04183 zone->link = 0;
04184 zone->ndescr = 0;
04185 zone->nzcoor = 0;
04186 zone->nsections = 0;
04187 zone->family_name[0]='\0';
04188 zone->nsols = 0;
04189 zone->ndiscrete = 0;
04190 zone->nintegrals = 0;
04191 zone->zconn = 0;
04192 zone->zboco = 0;
04193 zone->state = 0;
04194 zone->data_class = DataClassNull;
04195 zone->units = 0;
04196 zone->equations = 0;
04197 zone->converg = 0;
04198 zone->ordinal = 0;
04199 zone->nrmotions = 0;
04200 zone->namotions = 0;
04201 zone->ziter = 0;
04202 zone->nuser_data= 0;
04203 zone->rotating = 0;
04204
04205
04206 dim_vals[0]=zone->index_dim;
04207 dim_vals[1]=3;
04208 if (cgi_new_node(base->id, zone->name, "Zone_t", &zone->id,
04209 "I4", 2, dim_vals, (void *)zone->nijk)) return CG_ERROR;
04210
04211 dim_vals[0] = strlen(ZoneTypeName[type]);
04212 if (cgi_new_node(zone->id, "ZoneType", "ZoneType_t", &dummy_id,
04213 "C1", 1, dim_vals, ZoneTypeName[type])) return CG_ERROR;
04214
04215 return CG_OK;
04216 }
04217
04218 int cg_family_write(int file_number, int B, char const * family_name, int *F) {
04219 int index;
04220 cgns_base *base;
04221 cgns_family *family = NULL;
04222
04223
04224 if (cgi_check_strlen(family_name)) return CG_ERROR;
04225
04226 cg = cgi_get_file(file_number);
04227 if (cg == 0) return CG_ERROR;
04228
04229 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
04230
04231
04232 base = cgi_get_base(cg, B);
04233 if (base==0) return CG_ERROR;
04234
04235
04236 for (index=0; index<base->nfamilies; index++) {
04237 if (strcmp(family_name, base->family[index].name)==0) {
04238
04239
04240 if (cg->mode==CG_MODE_WRITE) {
04241 cgi_error("Duplicate child name found: %s",family_name);
04242 return CG_ERROR;
04243 }
04244
04245
04246
04247 if (cgi_delete_node(base->id, base->family[index].id))
04248 return CG_ERROR;
04249
04250 family = &(base->family[index]);
04251
04252 cgi_free_family(family);
04253 break;
04254 }
04255 }
04256
04257 if (index==base->nfamilies) {
04258 if (base->nfamilies == 0) {
04259 base->family = CGNS_NEW(cgns_family, base->nfamilies+1);
04260 } else {
04261 base->family = CGNS_RENEW(cgns_family, base->nfamilies+1, base->family);
04262 }
04263 family = &(base->family[base->nfamilies]);
04264 base->nfamilies++;
04265 }
04266 (*F) = index+1;
04267
04268 strcpy(family->name, family_name);
04269 family->id=0;
04270 family->link = 0;
04271 family->ndescr = 0;
04272 family->nfambc = 0;
04273 family->ngeos = 0;
04274 family->ordinal = 0;
04275 family->nuser_data= 0;
04276 family->rotating = 0;
04277
04278
04279 if (cgi_new_node(base->id, family->name, "Family_t", &family->id,
04280 "MT", 0, 0, 0)) return CG_ERROR;
04281
04282 return CG_OK;
04283 }
04284
04285 int cg_fambc_write(int file_number, int B, int F, char const * fambc_name,
04286 BCType_t bocotype, int *BC) {
04287 int index, length;
04288 cgns_family *family;
04289 cgns_fambc *fambc = NULL;
04290
04291
04292 if (cgi_check_strlen(fambc_name)) return CG_ERROR;
04293 if (bocotype<0 || bocotype>=NofValidBCTypes) {
04294 cgi_error("Invalid BCType: %d",bocotype);
04295 return CG_ERROR;
04296 }
04297
04298 cg = cgi_get_file(file_number);
04299 if (cg == 0) return CG_ERROR;
04300
04301 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
04302
04303
04304 family = cgi_get_family(cg, B, F);
04305 if (family==0) return CG_ERROR;
04306
04307
04308 for (index=0; index<family->nfambc; index++) {
04309 if (strcmp(fambc_name, family->fambc[index].name)==0) {
04310
04311
04312 if (cg->mode==CG_MODE_WRITE) {
04313 cgi_error("Duplicate child name found: %s",fambc_name);
04314 return CG_ERROR;
04315 }
04316
04317
04318
04319 if (cgi_delete_node(family->id, family->fambc[index].id))
04320 return CG_ERROR;
04321
04322 fambc = &(family->fambc[index]);
04323
04324 cgi_free_fambc(fambc);
04325 break;
04326 }
04327 }
04328
04329 if (index==family->nfambc) {
04330 if (family->nfambc == 0) {
04331 family->fambc = CGNS_NEW(cgns_fambc, family->nfambc+1);
04332 } else {
04333 family->fambc = CGNS_RENEW(cgns_fambc, family->nfambc+1, family->fambc);
04334 }
04335 fambc = &(family->fambc[family->nfambc]);
04336 family->nfambc++;
04337 }
04338 (*BC) = index+1;
04339
04340 strcpy(fambc->name, fambc_name);
04341 fambc->id=0;
04342 fambc->link = 0;
04343 fambc->type = bocotype;
04344 fambc->ndataset = 0;
04345 fambc->dataset = 0;
04346
04347
04348 length = strlen(BCTypeName[bocotype]);
04349 if (cgi_new_node(family->id, fambc->name, "FamilyBC_t", &fambc->id,
04350 "C1", 1, &length, BCTypeName[bocotype])) return CG_ERROR;
04351 return CG_OK;
04352 }
04353
04354 int cg_geo_write(int file_number, int B, int F, char const * geo_name,
04355 char const * filename, char const * CADname, int *G) {
04356 int index, length;
04357 cgns_family *family;
04358 cgns_geo *geo = NULL;
04359 double dummy_id;
04360
04361
04362 if (cgi_check_strlen(geo_name)) return CG_ERROR;
04363 if (cgi_check_strlen(CADname)) return CG_ERROR;
04364
04365 cg = cgi_get_file(file_number);
04366 if (cg == 0) return CG_ERROR;
04367
04368 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
04369
04370
04371 family = cgi_get_family(cg, B, F);
04372 if (family==0) return CG_ERROR;
04373
04374
04375 for (index=0; index<family->ngeos; index++) {
04376 if (strcmp(geo_name, family->geo[index].name)==0) {
04377
04378
04379 if (cg->mode==CG_MODE_WRITE) {
04380 cgi_error("Duplicate child name found: %s",geo_name);
04381 return CG_ERROR;
04382 }
04383
04384
04385
04386 if (cgi_delete_node(family->id, family->geo[index].id))
04387 return CG_ERROR;
04388
04389 geo = &(family->geo[index]);
04390
04391 cgi_free_geo(geo);
04392 break;
04393 }
04394 }
04395
04396 if (index==family->ngeos) {
04397 if (family->ngeos == 0) {
04398 family->geo = CGNS_NEW(cgns_geo, family->ngeos+1);
04399 } else {
04400 family->geo = CGNS_RENEW(cgns_geo, family->ngeos+1, family->geo);
04401 }
04402 geo = &(family->geo[family->ngeos]);
04403 family->ngeos++;
04404 }
04405 (*G) = index+1;
04406
04407
04408 strcpy(geo->name, geo_name);
04409 strcpy(geo->format, CADname);
04410 geo->id=0;
04411 geo->link=0;
04412 geo->ndescr=0;
04413 geo->npart=0;
04414 geo->nuser_data=0;
04415
04416 length = strlen(filename);
04417 if (length<=0) {
04418 cgi_error("filename undefined for GeometryReference node!");
04419 return CG_ERROR;
04420 }
04421 geo->file = (char *)malloc((length+1)*sizeof(char));
04422 strcpy(geo->file, filename);
04423
04424
04425 if (cgi_new_node(family->id, geo->name, "GeometryReference_t", &geo->id,
04426 "MT", 0, 0, 0)) return CG_ERROR;
04427 length = strlen(geo->file);
04428 if (cgi_new_node(geo->id, "GeometryFile", "GeometryFile_t", &dummy_id,
04429 "C1", 1, &length, geo->file)) return CG_ERROR;
04430 length = strlen(geo->format);
04431 if (cgi_new_node(geo->id, "GeometryFormat", "GeometryFormat_t", &dummy_id,
04432 "C1", 1, &length, geo->format)) return CG_ERROR;
04433 return CG_OK;
04434 }
04435
04436 int cg_part_write(int file_number, int B, int F, int G, char const * part_name,
04437 int *P) {
04438 int index;
04439 cgns_geo *geo;
04440 cgns_part *part = NULL;
04441 cgns_family *family;
04442
04443
04444 if (cgi_check_strlen(part_name)) return CG_ERROR;
04445
04446 cg = cgi_get_file(file_number);
04447 if (cg == 0) return CG_ERROR;
04448
04449 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
04450
04451
04452 family = cgi_get_family(cg, B, F);
04453 if (family==0) return CG_ERROR;
04454 if (G > family->ngeos || G <=0) {
04455 cgi_error("Invalid index for GeometryEntity_t node");
04456 return CG_ERROR;
04457 }
04458 geo = &family->geo[G-1];
04459
04460
04461 for (index=0; index<geo->npart; index++) {
04462 if (strcmp(part_name, geo->part[index].name)==0) {
04463
04464
04465 if (cg->mode==CG_MODE_WRITE) {
04466 cgi_error("Duplicate child name found: %s",part_name);
04467 return CG_ERROR;
04468 }
04469
04470
04471
04472 if (cgi_delete_node(geo->id, geo->part[index].id))
04473 return CG_ERROR;
04474
04475 part = &(geo->part[index]);
04476
04477 cgi_free_part(part);
04478 break;
04479 }
04480 }
04481
04482 if (index==geo->npart) {
04483 if (geo->npart == 0) {
04484 geo->part = CGNS_NEW(cgns_part, geo->npart+1);
04485 } else {
04486 geo->part = CGNS_RENEW(cgns_part, geo->npart+1, geo->part);
04487 }
04488 part = &(geo->part[geo->npart]);
04489 geo->npart++;
04490 }
04491 (*P) = index+1;
04492
04493 strcpy(part->name, part_name);
04494 part->id=0;
04495 part->link=0;
04496
04497
04498 if (cgi_new_node(geo->id, part->name, "GeometryEntity_t", &part->id,
04499 "MT", 0, 0, 0)) return CG_ERROR;
04500 return CG_OK;
04501 }
04502
04503 int cg_discrete_write(int file_number, int B, int Z, char const * discrete_name, int *D) {
04504 cgns_zone *zone;
04505 cgns_discrete *discrete = NULL;
04506 int index;
04507
04508
04509 if (cgi_check_strlen(discrete_name)) return CG_ERROR;
04510
04511 cg = cgi_get_file(file_number);
04512 if (cg == 0) return CG_ERROR;
04513
04514 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
04515
04516 zone = cgi_get_zone(cg, B, Z);
04517 if (zone==0) return CG_ERROR;
04518
04519
04520 for (index=0; index<zone->ndiscrete; index++) {
04521 if (strcmp(discrete_name, zone->discrete[index].name)==0) {
04522
04523
04524 if (cg->mode==CG_MODE_WRITE) {
04525 cgi_error("Duplicate child name found: %s",discrete_name);
04526 return CG_ERROR;
04527 }
04528
04529
04530
04531 if (cgi_delete_node(zone->id, zone->discrete[index].id))
04532 return CG_ERROR;
04533
04534 discrete = &(zone->discrete[index]);
04535
04536 cgi_free_discrete(discrete);
04537 break;
04538 }
04539 }
04540
04541 if (index==zone->ndiscrete) {
04542 if (zone->ndiscrete == 0) {
04543 zone->discrete = CGNS_NEW(cgns_discrete, zone->ndiscrete+1);
04544 } else {
04545 zone->discrete = CGNS_RENEW(cgns_discrete, zone->ndiscrete+1, zone->discrete);
04546 }
04547 discrete = &zone->discrete[zone->ndiscrete];
04548 zone->ndiscrete++;
04549 }
04550 (*D) = index+1;
04551
04552
04553 strcpy(discrete->name, discrete_name);
04554
04555
04556 discrete->id = 0;
04557 discrete->link=0;
04558 discrete->ndescr=0;
04559 discrete->location=Vertex;
04560 discrete->rind_planes=0;
04561 discrete->narrays=0;
04562 discrete->data_class=DataClassNull;
04563 discrete->units=0;
04564 discrete->nuser_data=0;
04565
04566
04567 if (cgi_new_node(zone->id, discrete->name, "DiscreteData_t", &discrete->id,
04568 "MT", 0, 0, 0)) return CG_ERROR;
04569 return CG_OK;
04570 }
04571
04572
04573 int cg_coord_write(int file_number, int B, int Z, DataType_t type, char const * coordname,
04574 void const * coord_ptr, int *C) {
04575 cgns_zone *zone;
04576 cgns_zcoor *zcoor;
04577 cgns_array *coord;
04578 int n, index, index_dim;
04579
04580
04581 if (cgi_check_strlen(coordname)) return CG_ERROR;
04582 if (type!=RealSingle && type!=RealDouble) {
04583 cgi_error("Invalid datatype for coord. array: %d", type);
04584 return CG_ERROR;
04585 }
04586
04587 cg = cgi_get_file(file_number);
04588 if (cg == 0) return CG_ERROR;
04589
04590 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
04591
04592
04593 zone = cgi_get_zone(cg, B, Z);
04594 if (zone==0) return CG_ERROR;
04595
04596
04597 zcoor = cgi_get_zcoorGC(cg, B, Z);
04598 if (zcoor==0) return CG_ERROR;
04599
04600
04601 for (index=0; index<zcoor->ncoords; index++) {
04602 if (strcmp(coordname, zcoor->coord[index].name)==0) {
04603 coord = &(zcoor->coord[index]);
04604
04605
04606 if (cg->mode==CG_MODE_WRITE) {
04607 cgi_error("Duplicate child name found: %s",coordname);
04608 return CG_ERROR;
04609 }
04610
04611
04612 if (type==cgi_datatype(coord->data_type)) {
04613 if (cgio_write_all_data(cg->cgio, coord->id, coord_ptr)) {
04614 cg_io_error("cgio_write_all_data");
04615 return CG_ERROR;
04616 }
04617 (*C) = index+1;
04618 return CG_OK;
04619 }
04620 cgi_error("To overwrite array %s, use data-type '%s'",
04621 coord->name, DataTypeName[cgi_datatype(coord->data_type)]);
04622 return CG_ERROR;
04623 }
04624 }
04625
04626
04627 if (zcoor->ncoords == 0) {
04628 zcoor->coord = CGNS_NEW(cgns_array, zcoor->ncoords+1);
04629 } else {
04630 zcoor->coord = CGNS_RENEW(cgns_array, zcoor->ncoords+1, zcoor->coord);
04631 }
04632 coord = &(zcoor->coord[zcoor->ncoords]);
04633 zcoor->ncoords++;
04634 (*C) = zcoor->ncoords;
04635
04636
04637 strcpy(coord->data_type,cgi_adf_datatype(type));
04638 strcpy(coord->name,coordname);
04639 coord->id=0;
04640 coord->link=0;
04641 index_dim = zone->index_dim;
04642 for (n=0; n<index_dim; n++)
04643 coord->dim_vals[n] = zone->nijk[n] + zcoor->rind_planes[2*n]
04644 + zcoor->rind_planes[2*n+1];
04645 coord->data_dim=index_dim;
04646 coord->data=0;
04647 coord->ndescr=0;
04648 coord->data_class=DataClassNull;
04649 coord->units=0;
04650 coord->exponents=0;
04651 coord->convert=0;
04652
04653
04654 if (zcoor->id == 0) {
04655 if (cgi_new_node(zone->id, "GridCoordinates", "GridCoordinates_t",
04656 &zcoor->id, "MT", 0, 0, 0)) return CG_ERROR;
04657 }
04658
04659 if (cgi_new_node(zcoor->id, coord->name, "DataArray_t", &coord->id,
04660 coord->data_type, index_dim, coord->dim_vals, coord_ptr)) return CG_ERROR;
04661
04662 return CG_OK;
04663 }
04664
04665 int cg_section_write(int file_number, int B, int Z, char const * SectionName, ElementType_t type,
04666 int start, int end, int nbndry, int const * elements, int *S) {
04667 cgns_zone *zone;
04668 cgns_section *section = NULL;
04669 int index, num;
04670 int ElementDataSize=0;
04671
04672
04673 if (cgi_check_strlen(SectionName)) return CG_ERROR;
04674
04675 if (type < 0 || type >= NofValidElementTypes) {
04676 cgi_error("Invalid element type defined for section '%s'",SectionName);
04677 return CG_ERROR;
04678 }
04679 if ((end-start)<0) {
04680 cgi_error("Invalid element range defined for section '%s'",SectionName);
04681 return CG_ERROR;
04682 }
04683 if (nbndry>(end-start+1)) {
04684 cgi_error("Invalid boundary element number for section '%s'",SectionName);
04685 return CG_ERROR;
04686 }
04687
04688
04689 cg = cgi_get_file(file_number);
04690 if (cg == 0) return CG_ERROR;
04691
04692 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
04693
04694 zone = cgi_get_zone(cg, B, Z);
04695 if (zone==0) return CG_ERROR;
04696
04697
04698 for (index=0; index<zone->nsections; index++) {
04699 if (strcmp(SectionName, zone->section[index].name)==0) {
04700
04701
04702 if (cg->mode==CG_MODE_WRITE) {
04703 cgi_error("Duplicate child name found: %s",SectionName);
04704 return CG_ERROR;
04705 }
04706
04707
04708
04709 if (cgi_delete_node(zone->id, zone->section[index].id))
04710 return CG_ERROR;
04711
04712 section = &(zone->section[index]);
04713
04714 cgi_free_section(section);
04715 break;
04716 }
04717 }
04718
04719 if (index==zone->nsections) {
04720 if (zone->nsections == 0) {
04721 zone->section = CGNS_NEW(cgns_section, zone->nsections+1);
04722 } else {
04723 zone->section = CGNS_RENEW(cgns_section, zone->nsections+1, zone->section);
04724 }
04725 section = &(zone->section[zone->nsections]);
04726 zone->nsections++;
04727 }
04728 (*S) = index+1;
04729
04730
04731 strcpy(section->name, SectionName);
04732 section->el_type = type;
04733 section->range[0] = start;
04734 section->range[1] = end;
04735 section->el_bound = nbndry;
04736
04737
04738 num = end - start +1;
04739 ElementDataSize = cgi_element_data_size(type, num, elements);
04740 if (ElementDataSize < 0) return CG_ERROR;
04741
04742
04743 section->connect = CGNS_NEW(cgns_array, 1);
04744 section->connect->data = (void *)malloc(ElementDataSize*sizeof(int));
04745 memcpy(section->connect->data, elements, ElementDataSize*sizeof(int));
04746 strcpy(section->connect->name,"ElementConnectivity");
04747 strcpy(section->connect->data_type,"I4");
04748 section->connect->data_dim=1;
04749 section->connect->dim_vals[0]=ElementDataSize;
04750
04751
04752 section->id=0;
04753 section->link=0;
04754 section->ndescr=0;
04755 section->parent=0;
04756 section->nuser_data=0;
04757 section->rind_planes=0;
04758
04759
04760 section->connect->id=0;
04761 section->connect->link=0;
04762 section->connect->ndescr=0;
04763 section->connect->data_class=DataClassNull;
04764 section->connect->units=0;
04765 section->connect->exponents=0;
04766 section->connect->convert=0;
04767
04768
04769 if (cgi_write_section(zone->id, section)) return CG_ERROR;
04770 return CG_OK;
04771 }
04772
04773 int cg_parent_data_write(int file_number, int B, int Z, int S, int const * parent_data) {
04774 cgns_section *section;
04775 cgns_array *parent;
04776 int num;
04777
04778
04779 cg = cgi_get_file(file_number);
04780 if (cg == 0) return CG_ERROR;
04781
04782 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
04783
04784 section = cgi_get_section(cg, B, Z, S);
04785 if (section == 0) return CG_ERROR;
04786
04787 if (section->parent) {
04788 if (cg->mode==CG_MODE_WRITE) {
04789 cgi_error("ParentData is already defined under Elements_t '%s'",
04790 section->name);
04791 return CG_ERROR;
04792 }
04793 if (cgi_delete_node(section->id, section->parent->id))
04794 return CG_ERROR;
04795 cgi_free_array(section->parent);
04796 } else
04797 section->parent = CGNS_NEW(cgns_array, 1);
04798 parent = section->parent;
04799
04800 num = section->range[1]-section->range[0]+1;
04801 strcpy(parent->data_type, "I4");
04802 parent->data = (void *)malloc(num*4*sizeof(int));
04803 if (!parent->data) {
04804 cgi_error("Error allocating parent->data");
04805 return CG_ERROR;
04806 }
04807 memcpy(parent->data, parent_data, num*4*sizeof(int));
04808 strcpy(parent->name, "ParentData");
04809 parent->data_dim =2;
04810 parent->dim_vals[0]=num;
04811 parent->dim_vals[1]=4;
04812
04813
04814 parent->id=0;
04815 parent->link=0;
04816 parent->ndescr=0;
04817 parent->data_class=DataClassNull;
04818 parent->units=0;
04819 parent->exponents=0;
04820 parent->convert=0;
04821
04822 if(cgi_write_array(section->id, section->parent)) return CG_ERROR;
04823 return CG_OK;
04824 }
04825
04826 int cg_grid_write(int file_number, int B, int Z, char const * zcoorname, int *G) {
04827 cgns_zone *zone;
04828 cgns_zcoor *zcoor = NULL;
04829 int index, n, index_dim;
04830
04831
04832 if (cgi_check_strlen(zcoorname)) return CG_ERROR;
04833
04834
04835 cg = cgi_get_file(file_number);
04836 if (cg == 0) return CG_ERROR;
04837
04838 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
04839
04840 zone = cgi_get_zone(cg, B, Z);
04841 if (zone==0) return CG_ERROR;
04842
04843
04844 for (index=0; index<zone->nzcoor; index++) {
04845 if (strcmp(zcoorname, zone->zcoor[index].name)==0) {
04846
04847
04848 if (cg->mode==CG_MODE_WRITE) {
04849 cgi_error("Duplicate child name found: %s",zcoorname);
04850 return CG_ERROR;
04851 }
04852
04853
04854
04855 if (cgi_delete_node(zone->id, zone->zcoor[index].id))
04856 return CG_ERROR;
04857
04858 zcoor = &(zone->zcoor[index]);
04859
04860 cgi_free_zcoor(zcoor);
04861 break;
04862 }
04863 }
04864
04865 if (index==zone->nzcoor) {
04866 if (zone->nzcoor == 0) {
04867 zone->zcoor = CGNS_NEW(cgns_zcoor, 1);
04868 } else {
04869 zone->zcoor = CGNS_RENEW(cgns_zcoor, zone->nzcoor+1, zone->zcoor);
04870 }
04871 zcoor = &(zone->zcoor[zone->nzcoor]);
04872 zone->nzcoor++;
04873 }
04874 (*G) = index+1;
04875
04876
04877 strcpy(zcoor->name,zcoorname);
04878
04879
04880 zcoor->ncoords = 0;
04881 zcoor->id=0;
04882 zcoor->link=0;
04883 zcoor->ndescr=0;
04884 zcoor->data_class=DataClassNull;
04885 zcoor->units=0;
04886 zcoor->nuser_data=0;
04887
04888 index_dim = zone->index_dim;
04889 zcoor->rind_planes = (int *)malloc(index_dim*2*sizeof(int));
04890 if (!zcoor->rind_planes) {
04891 cgi_error("Error allocating zcoor->rind_plane.");
04892 return CG_ERROR;
04893 }
04894 for (n=0; n<index_dim; n++)
04895 zcoor->rind_planes[2*n]=zcoor->rind_planes[2*n+1]=0;
04896
04897
04898 if (cgi_new_node(zone->id, zcoor->name, "GridCoordinates_t", &zcoor->id,
04899 "MT", 0, 0, 0)) return CG_ERROR;
04900
04901 return CG_OK;
04902 }
04903
04904 int cg_sol_write(int file_number, int B, int Z, char const * solname,
04905 GridLocation_t location, int *S) {
04906 cgns_zone *zone;
04907 cgns_sol *sol = NULL;
04908 int index, n, index_dim;
04909
04910
04911 if (cgi_check_strlen(solname)) return CG_ERROR;
04912 if (location != Vertex && location != CellCenter &&
04913 location !=IFaceCenter && location != JFaceCenter &&
04914 location != KFaceCenter) {
04915 cgi_error("Given grid location not supported for FlowSolution_t");
04916 return CG_ERROR;
04917 }
04918
04919
04920
04921
04922
04923
04924 cg = cgi_get_file(file_number);
04925 if (cg == 0) return CG_ERROR;
04926
04927 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
04928
04929 zone = cgi_get_zone(cg, B, Z);
04930 if (zone==0) return CG_ERROR;
04931 if (zone->type != Structured && (location == IFaceCenter ||
04932 location == JFaceCenter || location == KFaceCenter)) {
04933 cgi_error ("GridLocation [IJK]FaceCenter only valid for Structured grid");
04934 return CG_ERROR;
04935 }
04936
04937
04938 for (index=0; index<zone->nsols; index++) {
04939 if (strcmp(solname, zone->sol[index].name)==0) {
04940
04941
04942 if (cg->mode==CG_MODE_WRITE) {
04943 cgi_error("Duplicate child name found: %s",solname);
04944 return CG_ERROR;
04945 }
04946
04947
04948
04949 if (cgi_delete_node(zone->id, zone->sol[index].id))
04950 return CG_ERROR;
04951
04952 sol = &(zone->sol[index]);
04953
04954 cgi_free_sol(sol);
04955 break;
04956 }
04957 }
04958
04959 if (index==zone->nsols) {
04960 if (zone->nsols == 0) {
04961 zone->sol = CGNS_NEW(cgns_sol, zone->nsols+1);
04962 } else {
04963 zone->sol = CGNS_RENEW(cgns_sol, zone->nsols+1, zone->sol);
04964 }
04965 sol = &(zone->sol[zone->nsols]);
04966 zone->nsols++;
04967 }
04968 (*S) = index+1;
04969
04970
04971 strcpy(sol->name,solname);
04972 sol->location = location;
04973
04974
04975 sol->nfields = 0;
04976 sol->id=0;
04977 sol->link=0;
04978 sol->ndescr=0;
04979 sol->data_class=DataClassNull;
04980 sol->units=0;
04981 sol->nuser_data=0;
04982
04983 index_dim = zone->index_dim;
04984 sol->rind_planes = (int *)malloc(index_dim*2*sizeof(int));
04985 if (!sol->rind_planes) {
04986 cgi_error("Error allocating sol->rind_plane.");
04987 return CG_ERROR;
04988 }
04989 for (n=0; n<index_dim; n++)
04990 sol->rind_planes[2*n]=sol->rind_planes[2*n+1]=0;
04991
04992
04993 if (cgi_new_node(zone->id, sol->name, "FlowSolution_t", &sol->id,
04994 "MT", 0, 0, 0)) return CG_ERROR;
04995 if (sol->location != Vertex) {
04996 int length = strlen(GridLocationName[sol->location]);
04997 double GL_id;
04998 if (cgi_new_node(sol->id, "GridLocation", "GridLocation_t", &GL_id,
04999 "C1", 1, &length, (void *)GridLocationName[sol->location])) return CG_ERROR;
05000 }
05001
05002 return CG_OK;
05003 }
05004
05005 int cg_field_write(int file_number, int B, int Z, int S, DataType_t type, char const * fieldname,
05006 void const * field_ptr, int *F) {
05007 cgns_zone *zone;
05008 cgns_sol *sol;
05009 cgns_array *field;
05010 int index, index_dim;
05011
05012
05013 if (cgi_check_strlen(fieldname)) return CG_ERROR;
05014 if (type!=RealSingle && type!=RealDouble && type!=Integer) {
05015 cgi_error("Invalid datatype for solution array %s: %d",fieldname, type);
05016 return CG_ERROR;
05017 }
05018
05019 cg = cgi_get_file(file_number);
05020 if (cg == 0) return CG_ERROR;
05021
05022 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
05023
05024 zone = cgi_get_zone(cg, B, Z);
05025 if (zone==0) return CG_ERROR;
05026
05027 sol = cgi_get_sol(cg, B, Z, S);
05028 if (sol==0) return CG_ERROR;
05029
05030 index_dim = zone->index_dim;
05031
05032
05033 for (index=0; index<sol->nfields; index++) {
05034 if (strcmp(fieldname, sol->field[index].name)==0) {
05035 field = &(sol->field[index]);
05036
05037
05038 if (cg->mode==CG_MODE_WRITE) {
05039 cgi_error("Duplicate child name found: %s",fieldname);
05040 return CG_ERROR;
05041 }
05042
05043
05044 if (type==cgi_datatype(field->data_type)) {
05045 if (cgio_write_all_data(cg->cgio, field->id, field_ptr)) {
05046 cg_io_error("cgio_write_all_data");
05047 return CG_ERROR;
05048 }
05049 (*F) = index+1;
05050 return CG_OK;
05051 }
05052 cgi_error("To overwrite array %s, use data-type '%s'",
05053 field->name, DataTypeName[cgi_datatype(field->data_type)]);
05054 return CG_ERROR;
05055 }
05056 }
05057
05058 if (sol->nfields == 0) {
05059 sol->field = CGNS_NEW(cgns_array, sol->nfields+1);
05060 } else {
05061 sol->field = CGNS_RENEW(cgns_array, sol->nfields+1, sol->field);
05062 }
05063 field = &(sol->field[sol->nfields]);
05064 sol->nfields++;
05065 (*F) = sol->nfields;
05066
05067
05068 strcpy(field->data_type, cgi_adf_datatype(type));
05069 strcpy(field->name,fieldname);
05070 field->data_dim = zone->index_dim;
05071 if (cgi_datasize(index_dim, zone->nijk, sol->location,
05072 sol->rind_planes, field->dim_vals)) return CG_ERROR;
05073
05074
05075 field->id = 0;
05076 field->link= 0;
05077 field->data=0;
05078 field->ndescr= 0;
05079 field->data_class= DataClassNull;
05080 field->units= 0;
05081 field->exponents= 0;
05082 field->convert= 0;
05083
05084
05085 if (cgi_new_node(sol->id, field->name, "DataArray_t", &field->id,
05086 field->data_type, index_dim, field->dim_vals, field_ptr)) return CG_ERROR;
05087
05088 return CG_OK;
05089 }
05090
05091 int cg_hole_write(int file_number, int B, int Z, char const * holename, GridLocation_t location,
05092 PointSetType_t ptset_type, int nptsets, int npnts, int const * pnts, int *I) {
05093 cgns_zone *zone;
05094 cgns_zconn *zconn;
05095 cgns_hole *hole = NULL;
05096 cgns_ptset *ptset;
05097 char_33 PointSetName;
05098 int index, set;
05099 int i, index_dim;
05100
05101
05102 if (cgi_check_strlen(holename)) return CG_ERROR;
05103 if (location != Vertex && location != CellCenter) {
05104 cgi_error("cg_hole_write: GridLocation not Vertex or CellCenter");
05105 return CG_ERROR;
05106 }
05107 if (ptset_type!=PointList && ptset_type!=PointRange) {
05108 cgi_error("Invalid input: ptset_type=%d ?",ptset_type);
05109 return CG_ERROR;
05110 }
05111 if (!(ptset_type==PointRange && npnts==2*nptsets && nptsets>0) &&
05112 !(ptset_type==PointList && npnts>=0 && nptsets==1)) {
05113 cgi_error("Invalid input: nptsets=%d, npoint=%d, point set type=%s",
05114 nptsets, npnts, PointSetTypeName[ptset_type]);
05115 return CG_ERROR;
05116 }
05117
05118 cg = cgi_get_file(file_number);
05119 if (cg == 0) return CG_ERROR;
05120
05121 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
05122
05123
05124 zone = cgi_get_zone(cg, B, Z);
05125 if (zone==0) return CG_ERROR;
05126
05127
05128 if (zone->zconn == 0) {
05129 zone->zconn = CGNS_NEW(cgns_zconn, 1);
05130 zconn = zone->zconn;
05131 strcpy(zconn->name,"ZoneGridConnectivity");
05132
05133
05134 zconn->id = 0;
05135 zconn->link= 0;
05136 zconn->ndescr = 0;
05137 zconn->n1to1 = 0;
05138 zconn->nconns = 0;
05139 zconn->nholes = 0;
05140 zconn->nuser_data= 0;
05141 } else zconn = zone->zconn;
05142
05143 index_dim = zone->index_dim;
05144
05145
05146 for (index=0; index<zconn->nholes; index++) {
05147 if (strcmp(holename, zconn->hole[index].name)==0) {
05148
05149
05150 if (cg->mode==CG_MODE_WRITE) {
05151 cgi_error("Duplicate child name found: %s",holename);
05152 return CG_ERROR;
05153 }
05154
05155
05156
05157 if (cgi_delete_node(zconn->id, zconn->hole[index].id))
05158 return CG_ERROR;
05159
05160 hole = &(zconn->hole[index]);
05161 cgi_free_hole(hole);
05162 break;
05163 }
05164 }
05165
05166 if (index==zconn->nholes) {
05167 if (zconn->nholes == 0) {
05168 zconn->hole = CGNS_NEW(cgns_hole, zconn->nholes+1);
05169 } else {
05170 zconn->hole = CGNS_RENEW(cgns_hole, zconn->nholes+1, zconn->hole);
05171 }
05172 hole = &(zconn->hole[zconn->nholes]);
05173 zconn->nholes++;
05174 }
05175 (*I) = index+1;
05176
05177
05178 strcpy(hole->name,holename);
05179 hole->location = location;
05180
05181 hole->nptsets = nptsets;
05182 hole->ptset = CGNS_NEW(cgns_ptset, nptsets);
05183 for (set=0; set<nptsets; set++) {
05184 ptset = &hole->ptset[set];
05185 ptset->type = ptset_type;
05186 strcpy(ptset->data_type,"I4");
05187 if (ptset_type==PointRange) ptset->npts = 2;
05188 else ptset->npts = npnts;
05189 ptset->id = 0;
05190 ptset->link = 0;
05191
05192
05193 if (ptset_type==PointList)
05194 ptset->size_of_patch=npnts;
05195 else if (ptset_type==PointRange) {
05196 ptset->size_of_patch = 1;
05197 for (i=0; i<index_dim; i++)
05198 ptset->size_of_patch *= (pnts[i+index_dim]-pnts[i]+1);
05199 }
05200 }
05201
05202
05203 hole->id=0;
05204 hole->link=0;
05205 hole->ndescr=0;
05206 hole->nuser_data=0;
05207
05208
05209 if (zconn->id==0) {
05210 if (cgi_new_node(zone->id, "ZoneGridConnectivity", "ZoneGridConnectivity_t",
05211 &zconn->id, "MT", 0, 0, 0)) return CG_ERROR;
05212 }
05213 if (cgi_new_node(zconn->id, hole->name, "OversetHoles_t",
05214 &hole->id, "MT", 0, 0, 0)) return CG_ERROR;
05215
05216 if (hole->location !=Vertex) {
05217 double GL_id;
05218 int length = strlen(GridLocationName[hole->location]);
05219 if (cgi_new_node(hole->id, "GridLocation", "GridLocation_t", &GL_id,
05220 "C1", 1, &length, GridLocationName[hole->location])) return CG_ERROR;
05221 }
05222
05223 for (set=0; set<nptsets; set++) {
05224 ptset = &hole->ptset[set];
05225
05226 if (ptset->npts>0) {
05227
05228 if (ptset->type==PointRange)
05229 sprintf(PointSetName, "PointRange%d",set+1);
05230 else
05231 sprintf(PointSetName, PointSetTypeName[ptset->type]);
05232 if (cgi_write_ptset(hole->id, PointSetName, ptset, index_dim,
05233 (void *)((int *)pnts+2*index_dim*set))) return CG_ERROR;
05234 }
05235 }
05236
05237 return CG_OK;
05238 }
05239
05240 int cg_conn_write(int file_number, int B, int Z, char const * connectname, GridLocation_t location,
05241 GridConnectivityType_t type, PointSetType_t ptset_type, int npnts, int const * pnts,
05242 char const * donorname, ZoneType_t donor_zonetype, PointSetType_t donor_ptset_type,
05243 DataType_t donor_datatype, int ndata_donor, void const * donor_data, int *I) {
05244 cgns_zone *zone;
05245 cgns_zconn *zconn;
05246 cgns_conn *conn = NULL;
05247 cgns_ptset *dptset;
05248 int i, size_of_zone, length;
05249 int PointListSize, cell_dim;
05250 int index, index_dim, index_dim_donor;
05251 double GL_id, C_id;
05252
05253
05254 if (cgi_check_strlen(connectname)) return CG_ERROR;
05255 if (cgi_check_strlen(donorname)) return CG_ERROR;
05256 if (type <0 || type >= NofValidGridConnectivityTypes) {
05257 cgi_error("Invalid input: GridConnectivityType=%d ?",type);
05258 return CG_ERROR;
05259 }
05260 if (location != Vertex && location != CellCenter &&
05261 location != FaceCenter && location != IFaceCenter &&
05262 location != JFaceCenter && location != KFaceCenter) {
05263 cgi_error("Invalid input: GridLocation=%d ?",location);
05264 return CG_ERROR;
05265 }
05266 if (type == Overset && location != Vertex && location != CellCenter) {
05267 cgi_error("GridLocation must be Vertex or CellCenter for Overset");
05268 return CG_ERROR;
05269 }
05270 if (ptset_type!=PointList && ptset_type!=PointRange) {
05271 cgi_error("Invalid input: ptset_type=%d ?",ptset_type);
05272 return CG_ERROR;
05273 }
05274 if (!(ptset_type==PointRange && npnts==2) && !(ptset_type==PointList && npnts>0)) {
05275 cgi_error("Invalid input: npoint=%d, point set type=%s",
05276 npnts, PointSetTypeName[ptset_type]);
05277 return CG_ERROR;
05278 }
05279 if (ndata_donor) {
05280 if (donor_ptset_type!=CellListDonor && donor_ptset_type!=PointListDonor) {
05281 cgi_error("Invalid point set type for donor %s",donorname);
05282 return CG_ERROR;
05283 }
05284 if (donor_datatype != Integer) {
05285 cgi_error("Invalid datatype for donor %s",donorname);
05286 return CG_ERROR;
05287 }
05288
05289
05290
05291
05292
05293
05294
05295
05296
05297
05298
05299
05300
05301
05302
05303
05304
05305
05306
05307
05308 } else {
05309 donor_ptset_type = PointSetTypeNull;
05310 donor_datatype = Integer;
05311 }
05312
05313
05314 cg = cgi_get_file(file_number);
05315 if (cg == 0) return CG_ERROR;
05316
05317 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
05318
05319
05320 zone = cgi_get_zone(cg, B, Z);
05321 if (zone==0) return CG_ERROR;
05322
05323 if ((location == IFaceCenter || location == JFaceCenter ||
05324 location == KFaceCenter) && zone->type != Structured) {
05325 cgi_error("GridLocation [IJK]FaceCenter only valid for Structured grids");
05326 return CG_ERROR;
05327 }
05328
05329
05330 if (zone->zconn == 0) {
05331 zone->zconn = CGNS_NEW(cgns_zconn, 1);
05332 zconn = zone->zconn;
05333 strcpy(zconn->name,"ZoneGridConnectivity");
05334
05335
05336 zconn->id = 0;
05337 zconn->link= 0;
05338 zconn->ndescr = 0;
05339 zconn->n1to1 = 0;
05340 zconn->nconns = 0;
05341 zconn->nholes = 0;
05342 zconn->nuser_data= 0;
05343 } else zconn = zone->zconn;
05344
05345
05346 index_dim = zone->index_dim;
05347 cell_dim=cg->base[B-1].cell_dim;
05348
05349
05350 size_of_zone = 1;
05351 for (i=0; i<index_dim; i++) size_of_zone*=zone->nijk[i];
05352 if (npnts<0 || npnts>size_of_zone) {
05353 cgi_error("Inconsistent number of points in point set");
05354 return CG_ERROR;
05355 }
05356 #if 0
05357 if (ptset_type==PointRange) {
05358 if (location == Vertex) {
05359 for (i=0; i<index_dim; i++) {
05360 if (pnts[i]<0 || pnts[i+index_dim]>zone->nijk[i]) {
05361 cgi_error("Invalid input range: %d->%d",pnts[i], pnts[i+index_dim]);
05362 return CG_ERROR;
05363 }
05364 }
05365 } else if (location == CellCenter) {
05366 for (i=0; i<index_dim; i++) {
05367 if (pnts[i]<0 || pnts[i+index_dim]>zone->nijk[i+index_dim]) {
05368 cgi_error("Invalid input range: %d->%d",pnts[i], pnts[i+index_dim]);
05369 return CG_ERROR;
05370 }
05371 }
05372 }
05373 }
05374 #endif
05375
05376
05377 if (ptset_type==PointRange) {
05378 PointListSize = 1;
05379 for (i=0; i<index_dim; i++) {
05380 PointListSize *= (pnts[i+index_dim]-pnts[i]+1);
05381 }
05382 } else PointListSize=npnts;
05383
05384 if (ndata_donor && type == Abutting1to1 && PointListSize != ndata_donor) {
05385 cgi_error("Invalid input for ndata_donor in cg_conn_write");
05386 return CG_ERROR;
05387 }
05388
05389
05390 for (index=0; index<zconn->nconns; index++) {
05391 if (strcmp(connectname, zconn->conn[index].name)==0) {
05392
05393
05394 if (cg->mode==CG_MODE_WRITE) {
05395 cgi_error("Duplicate child name found: %s",connectname);
05396 return CG_ERROR;
05397 }
05398
05399
05400
05401 if (cgi_delete_node(zconn->id, zconn->conn[index].id))
05402 return CG_ERROR;
05403
05404 conn = &(zconn->conn[index]);
05405 cgi_free_conn(conn);
05406 break;
05407 }
05408 }
05409
05410 if (index==zconn->nconns) {
05411 if (zconn->nconns == 0) {
05412 zconn->conn = CGNS_NEW(cgns_conn, zconn->nconns+1);
05413 } else {
05414 zconn->conn = CGNS_RENEW(cgns_conn, zconn->nconns+1, zconn->conn);
05415 }
05416 conn = &(zconn->conn[zconn->nconns]);
05417 zconn->nconns++;
05418 }
05419 (*I) = index+1;
05420
05421
05422 strcpy(conn->name,connectname);
05423 conn->type = type;
05424 conn->location = location;
05425 conn->ptset.id = 0;
05426 conn->ptset.link = 0;
05427 conn->ptset.type = ptset_type;
05428 strcpy(conn->ptset.data_type,"I4");
05429 conn->ptset.npts = npnts;
05430 conn->ptset.size_of_patch = PointListSize;
05431
05432
05433 conn->id=0;
05434 conn->link=0;
05435 conn->ndescr=0;
05436 conn->ordinal=0;
05437 conn->nuser_data=0;
05438 conn->cprop=0;
05439
05440
05441 strcpy(conn->donor,donorname);
05442 conn->interpolants = 0;
05443 dptset = &conn->dptset;
05444 dptset->id = 0;
05445 dptset->link = 0;
05446 strcpy(dptset->name,PointSetTypeName[donor_ptset_type]);
05447 dptset->type = donor_ptset_type;
05448 strcpy(dptset->data_type, cgi_adf_datatype(donor_datatype));
05449 dptset->npts = ndata_donor;
05450 dptset->size_of_patch = ndata_donor;
05451
05452
05453 if (zconn->id==0) {
05454 if (cgi_new_node(zone->id, "ZoneGridConnectivity", "ZoneGridConnectivity_t",
05455 &zconn->id, "MT", 0, 0, 0)) return CG_ERROR;
05456 }
05457
05458 length = strlen(conn->donor);
05459 if (cgi_new_node(zconn->id, conn->name, "GridConnectivity_t", &conn->id,
05460 "C1", 1, &length, conn->donor)) return CG_ERROR;
05461
05462
05463 length = strlen(GridConnectivityTypeName[conn->type]);
05464 if (cgi_new_node(conn->id,"GridConnectivityType","GridConnectivityType_t",
05465 &C_id, "C1", 1, &length, GridConnectivityTypeName[conn->type])) return CG_ERROR;
05466
05467
05468 if (conn->location != Vertex) {
05469 length = strlen(GridLocationName[conn->location]);
05470 if (cgi_new_node(conn->id, "GridLocation", "GridLocation_t", &GL_id,
05471 "C1", 1, &length, GridLocationName[conn->location])) return CG_ERROR;
05472 }
05473
05474
05475 if (npnts>0) {
05476 char_33 PointSetName;
05477 strcpy (PointSetName, PointSetTypeName[conn->ptset.type]);
05478 if (cgi_write_ptset(conn->id, PointSetName, &conn->ptset, index_dim,
05479 (void *)pnts)) return CG_ERROR;
05480
05481
05482 if (ndata_donor) {
05483 if (donor_zonetype==Structured)
05484 index_dim_donor = cell_dim;
05485 else
05486 index_dim_donor=1;
05487 strcpy (PointSetName, PointSetTypeName[donor_ptset_type]);
05488 if (cgi_write_ptset(conn->id, PointSetName, dptset, index_dim_donor,
05489 (void *)donor_data)) return CG_ERROR;
05490 }
05491 }
05492 return CG_OK;
05493 }
05494
05495 int cg_conn_write_short(int file_number, int B, int Z, char const * connectname,
05496 GridLocation_t location, GridConnectivityType_t type, PointSetType_t ptset_type,
05497 int npnts, int const * pnts, char const * donorname, int *I) {
05498 #if 0
05499 cgns_zone *zone;
05500 cgns_zconn *zconn;
05501 cgns_conn *conn;
05502 int i, size_of_zone, length;
05503 int PointListSize, cell_dim;
05504 int index, index_dim;
05505 double GL_id, C_id;
05506
05507
05508 if (cgi_check_strlen(connectname)) return CG_ERROR;
05509 if (cgi_check_strlen(donorname)) return CG_ERROR;
05510 if (type <0 || type >= NofValidGridConnectivityTypes) {
05511 cgi_error("Invalid input: GridConnectivityType=%d ?",type);
05512 return CG_ERROR;
05513 }
05514 if (location != Vertex && location != CellCenter &&
05515 location != FaceCenter && location != IFaceCenter &&
05516 location != JFaceCenter && location != KFaceCenter) {
05517 cgi_error("Invalid input: GridLocation=%d ?",location);
05518 return CG_ERROR;
05519 }
05520 if (type == Overset && location != Vertex && location != CellCenter) {
05521 cgi_error("GridLocation must be Vertex or CellCenter for Overset");
05522 return CG_ERROR;
05523 }
05524 if (ptset_type!=PointList && ptset_type!=PointRange) {
05525 cgi_error("Invalid input: ptset_type=%d ?",ptset_type);
05526 return CG_ERROR;
05527 }
05528 if (!(ptset_type==PointRange && npnts==2) && !(ptset_type==PointList && npnts>0)) {
05529 cgi_error("Invalid input: npoint=%d, point set type=%s",
05530 npnts, PointSetTypeName[ptset_type]);
05531 return CG_ERROR;
05532 }
05533
05534
05535 cg = cgi_get_file(file_number);
05536 if (cg == 0) return CG_ERROR;
05537
05538 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
05539
05540
05541 zone = cgi_get_zone(cg, B, Z);
05542 if (zone==0) return CG_ERROR;
05543
05544 if ((location == IFaceCenter || location == JFaceCenter ||
05545 location == KFaceCenter) && zone->type != Structured) {
05546 cgi_error("GridLocation [IJK]FaceCenter only valid for Structured grids");
05547 return CG_ERROR;
05548 }
05549
05550
05551 if (zone->zconn == 0) {
05552 zone->zconn = CGNS_NEW(cgns_zconn, 1);
05553 zconn = zone->zconn;
05554 strcpy(zconn->name,"ZoneGridConnectivity");
05555
05556
05557 zconn->id = 0;
05558 zconn->link= 0;
05559 zconn->ndescr = 0;
05560 zconn->n1to1 = 0;
05561 zconn->nconns = 0;
05562 zconn->nholes = 0;
05563 zconn->nuser_data= 0;
05564 } else zconn = zone->zconn;
05565
05566
05567 index_dim = zone->index_dim;
05568 cell_dim=cg->base[B-1].cell_dim;
05569
05570
05571 size_of_zone = 1;
05572 for (i=0; i<index_dim; i++) size_of_zone*=zone->nijk[i];
05573 if (npnts<0 || npnts>size_of_zone) {
05574 cgi_error("Inconsistent number of points in point set");
05575 return CG_ERROR;
05576 }
05577
05578
05579 if (ptset_type==PointRange) {
05580 PointListSize = 1;
05581 for (i=0; i<index_dim; i++) {
05582 PointListSize *= (pnts[i+index_dim]-pnts[i]+1);
05583 }
05584 } else PointListSize=npnts;
05585
05586
05587 for (index=0; index<zconn->nconns; index++) {
05588 if (strcmp(connectname, zconn->conn[index].name)==0) {
05589
05590
05591 if (cg->mode==CG_MODE_WRITE) {
05592 cgi_error("Duplicate child name found: %s",connectname);
05593 return CG_ERROR;
05594 }
05595
05596
05597
05598 if (cgi_delete_node(zconn->id, zconn->conn[index].id))
05599 return CG_ERROR;
05600
05601 conn = &(zconn->conn[index]);
05602 cgi_free_conn(conn);
05603 break;
05604 }
05605 }
05606
05607 if (index==zconn->nconns) {
05608 if (zconn->nconns == 0) {
05609 zconn->conn = CGNS_NEW(cgns_conn, zconn->nconns+1);
05610 } else {
05611 zconn->conn = CGNS_RENEW(cgns_conn, zconn->nconns+1, zconn->conn);
05612 }
05613 conn = &(zconn->conn[zconn->nconns]);
05614 zconn->nconns++;
05615 }
05616 (*I) = index+1;
05617
05618
05619 strcpy(conn->name,connectname);
05620 conn->type = type;
05621 conn->location = location;
05622 conn->ptset.id = 0;
05623 conn->ptset.link = 0;
05624 conn->ptset.type = ptset_type;
05625 strcpy(conn->ptset.data_type,"I4");
05626 conn->ptset.npts = npnts;
05627 conn->ptset.size_of_patch = PointListSize;
05628
05629
05630 conn->id=0;
05631 conn->link=0;
05632 conn->ndescr=0;
05633 conn->ordinal=0;
05634 conn->nuser_data=0;
05635 conn->cprop=0;
05636
05637
05638 strcpy(conn->donor,donorname);
05639 conn->interpolants = 0;
05640 conn->dptset.id = 0;
05641 conn->dptset.link = 0;
05642 strcpy(conn->dptset.name,PointSetTypeName[PointSetTypeNull]);
05643 conn->dptset.type = PointSetTypeNull;
05644 strcpy(conn->dptset.data_type, "MT");
05645 conn->dptset.npts = 0;
05646 conn->dptset.size_of_patch = 0;
05647
05648
05649 if (zconn->id==0) {
05650 if (cgi_new_node(zone->id, "ZoneGridConnectivity", "ZoneGridConnectivity_t",
05651 &zconn->id, "MT", 0, 0, 0)) return CG_ERROR;
05652 }
05653
05654 length = strlen(conn->donor);
05655 if (cgi_new_node(zconn->id, conn->name, "GridConnectivity_t", &conn->id,
05656 "C1", 1, &length, conn->donor)) return CG_ERROR;
05657
05658
05659 length = strlen(GridConnectivityTypeName[conn->type]);
05660 if (cgi_new_node(conn->id,"GridConnectivityType","GridConnectivityType_t",
05661 &C_id, "C1", 1, &length, GridConnectivityTypeName[conn->type])) return CG_ERROR;
05662
05663
05664 if (conn->location != Vertex) {
05665 length = strlen(GridLocationName[conn->location]);
05666 if (cgi_new_node(conn->id, "GridLocation", "GridLocation_t", &GL_id,
05667 "C1", 1, &length, GridLocationName[conn->location])) return CG_ERROR;
05668 }
05669
05670
05671 if (npnts>0) {
05672 char_33 PointSetName;
05673 strcpy (PointSetName, PointSetTypeName[conn->ptset.type]);
05674 if (cgi_write_ptset(conn->id, PointSetName, &conn->ptset, index_dim,
05675 (void *)pnts)) return CG_ERROR;
05676 }
05677 return CG_OK;
05678 #else
05679 return cg_conn_write (file_number, B, Z, connectname, location,
05680 type, ptset_type, npnts, pnts, donorname,
05681 ZoneTypeNull, PointSetTypeNull, DataTypeNull, 0, NULL, I);
05682 #endif
05683 }
05684
05685 int cg_conn_average_write(int file_number, int B, int Z, int I,
05686 AverageInterfaceType_t AverageInterfaceType) {
05687
05688 cgns_cprop *cprop;
05689 cgns_caverage *caverage;
05690 cgns_conn *conn;
05691 int length;
05692 double dummy_id;
05693
05694
05695 if (AverageInterfaceType<0 || AverageInterfaceType>=NofValidAverageInterfaceTypes) {
05696 cgi_error("Invalid AverageInterfaceType: %d",AverageInterfaceType);
05697 return CG_ERROR;
05698 }
05699
05700
05701 cg = cgi_get_file(file_number);
05702 if (cg == 0) return CG_ERROR;
05703
05704 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
05705
05706
05707 conn = cgi_get_conn(cg, B, Z, I);
05708 if (conn==0) return CG_ERROR;
05709
05710
05711 if (conn->cprop == 0) {
05712 conn->cprop = CGNS_NEW(cgns_cprop, 1);
05713 cprop = conn->cprop;
05714 strcpy(cprop->name,"GridConnectivityProperty");
05715 cprop->id=0;
05716 cprop->link=0;
05717 cprop->ndescr=0;
05718 cprop->nuser_data=0;
05719 cprop->cperio=0;
05720 cprop->caverage=0;
05721 } else cprop = conn->cprop;
05722
05723
05724 if (cprop->caverage) {
05725
05726 if (cg->mode==CG_MODE_WRITE) {
05727 cgi_error("AverageInterface_t already defined under GridConnectivityProperty_t");
05728 return CG_ERROR;
05729 }
05730
05731
05732
05733 if (cgi_delete_node(cprop->id, cprop->caverage->id))
05734 return CG_ERROR;
05735 cgi_free_caverage(cprop->caverage);
05736 } else
05737 cprop->caverage = CGNS_NEW(cgns_caverage, 1);
05738 caverage = cprop->caverage;
05739
05740
05741 caverage->type = AverageInterfaceType;
05742
05743
05744 strcpy(caverage->name,"AverageInterface");
05745 caverage->id = 0;
05746 caverage->link = 0;
05747 caverage->ndescr = 0;
05748 caverage->nuser_data = 0;
05749
05750
05751 if (cprop->id==0) {
05752 if (cgi_new_node(conn->id, "GridConnectivityProperty",
05753 "GridConnectivityProperty_t", &cprop->id, "MT", 0, 0, 0)) return CG_ERROR;
05754 }
05755
05756 if (cgi_new_node(cprop->id, "AverageInterface", "AverageInterface_t",
05757 &caverage->id, "MT", 0, 0, 0)) return CG_ERROR;
05758
05759
05760 length = strlen(AverageInterfaceTypeName[caverage->type]);
05761 if (cgi_new_node(caverage->id, "AverageInterfaceType", "AverageInterfaceType_t", &dummy_id,
05762 "C1", 1, &length, (void *)AverageInterfaceTypeName[caverage->type])) return CG_ERROR;
05763 return CG_OK;
05764 }
05765
05766 int cg_conn_periodic_write(int file_number, int B, int Z, int I,
05767 float const *RotationCenter, float const *RotationAngle,
05768 float const *Translation) {
05769 cgns_base *base;
05770 cgns_conn *conn;
05771 cgns_cprop *cprop;
05772 cgns_cperio *cperio;
05773 int n;
05774
05775
05776 cg = cgi_get_file(file_number);
05777 if (cg == 0) return CG_ERROR;
05778
05779 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
05780
05781
05782 base = cgi_get_base(cg, B);
05783 if (base==0) return CG_ERROR;
05784
05785
05786 conn = cgi_get_conn(cg, B, Z, I);
05787 if (conn==0) return CG_ERROR;
05788
05789
05790 if (conn->cprop == 0) {
05791 conn->cprop = CGNS_NEW(cgns_cprop, 1);
05792 cprop = conn->cprop;
05793 strcpy(cprop->name,"GridConnectivityProperty");
05794 cprop->id=0;
05795 cprop->link=0;
05796 cprop->ndescr=0;
05797 cprop->nuser_data=0;
05798 cprop->cperio=0;
05799 cprop->caverage=0;
05800 } else cprop = conn->cprop;
05801
05802
05803 if (cprop->cperio) {
05804
05805 if (cg->mode==CG_MODE_WRITE) {
05806 cgi_error("Periodic_t already defined under GridConnectivityProperty_t.");
05807 return CG_ERROR;
05808 }
05809
05810
05811
05812 if (cgi_delete_node(cprop->id, cprop->cperio->id))
05813 return CG_ERROR;
05814 cgi_free_cperio(cprop->cperio);
05815 } else
05816 cprop->cperio = CGNS_NEW(cgns_cperio, 1);
05817 cperio = cprop->cperio;
05818
05819
05820 strcpy(cperio->name,"Periodic");
05821 cperio->id = 0;
05822 cperio->link = 0;
05823 cperio->ndescr = 0;
05824 cperio->nuser_data = 0;
05825 cperio->narrays = 3;
05826 cperio->data_class=DataClassNull;
05827 cperio->units=0;
05828
05829
05830 cperio->array = CGNS_NEW(cgns_array, 3);
05831
05832 for (n=0; n<cperio->narrays; n++) {
05833 strcpy(cperio->array[n].data_type, "R4");
05834 cperio->array[n].data = (void *)malloc(base->phys_dim*sizeof(float));
05835 if (!cperio->array[n].data) {
05836 cgi_error("Error allocating cperio->array[n].data");
05837 return CG_ERROR;
05838 }
05839 cperio->array[n].data_dim=1;
05840 cperio->array[n].dim_vals[0]=base->phys_dim;
05841 cperio->array[n].id=0;
05842 cperio->array[n].link=0;
05843 cperio->array[n].ndescr=0;
05844 cperio->array[n].data_class=DataClassNull;
05845 cperio->array[n].units=0;
05846 cperio->array[n].exponents=0;
05847 cperio->array[n].convert=0;
05848 }
05849 memcpy(cperio->array[0].data,RotationCenter,base->phys_dim*sizeof(float));
05850 memcpy(cperio->array[1].data,RotationAngle,base->phys_dim*sizeof(float));
05851 memcpy(cperio->array[2].data,Translation,base->phys_dim*sizeof(float));
05852 strcpy(cperio->array[0].name,"RotationCenter");
05853 strcpy(cperio->array[1].name,"RotationAngle");
05854 strcpy(cperio->array[2].name,"Translation");
05855
05856
05857 if (cprop->id==0) {
05858 if (cgi_new_node(conn->id, "GridConnectivityProperty",
05859 "GridConnectivityProperty_t", &cprop->id, "MT", 0, 0, 0)) return CG_ERROR;
05860 }
05861
05862 if (cgi_new_node(cprop->id, "Periodic", "Periodic_t",
05863 &cperio->id, "MT", 0, 0, 0)) return CG_ERROR;
05864
05865
05866 for (n=0; n<cperio->narrays; n++)
05867 if (cgi_write_array(cperio->id, &cperio->array[n])) return CG_ERROR;
05868 return CG_OK;
05869 }
05870
05871 int cg_1to1_write(int file_number, int B, int Z, char const * connectname, char const * donorname,
05872 int const * range, int const * donor_range, int const * transform, int *I) {
05873 cgns_zone *zone;
05874 cgns_zconn *zconn;
05875 cgns_1to1 *one21 = NULL;
05876 int index, i, j, index_dim, length;
05877 double T_id;
05878
05879
05880 if (cgi_check_strlen(connectname)) return CG_ERROR;
05881 if (cgi_check_strlen(donorname)) return CG_ERROR;
05882
05883
05884 cg = cgi_get_file(file_number);
05885 if (cg == 0) return CG_ERROR;
05886
05887 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
05888
05889
05890 zone = cgi_get_zone(cg, B, Z);
05891 if (zone==0) return CG_ERROR;
05892
05893
05894 if (zone->zconn == 0) {
05895 zone->zconn = CGNS_NEW(cgns_zconn, 1);
05896 zconn = zone->zconn;
05897 strcpy(zconn->name,"ZoneGridConnectivity");
05898
05899
05900 zconn->id = 0;
05901 zconn->link= 0;
05902 zconn->ndescr = 0;
05903 zconn->n1to1 = 0;
05904 zconn->nconns = 0;
05905 zconn->nholes = 0;
05906 zconn->nuser_data= 0;
05907
05908 } else zconn = zone->zconn;
05909
05910
05911 index_dim = zone->index_dim;
05912 for (i=0; i<index_dim; i++) {
05913 if (range[i]<=0 || range[i+index_dim]>zone->nijk[i]) {
05914 cgi_error("Invalid input range: %d->%d",range[i], range[i+index_dim]);
05915 return CG_ERROR;
05916 }
05917 if (abs(transform[i])<0 || abs(transform[i])>index_dim) {
05918 cgi_error("Invalid transformation index: %d. The indices must all be between 1 and %d",i, index_dim);
05919 return CG_ERROR;
05920 }
05921 if (abs(transform[i])>0) {
05922 j = abs(transform[i])-1;
05923 if (abs(range[i+index_dim]-range[i])-abs(donor_range[j+index_dim]-donor_range[j]) != 0) {
05924 cgi_error("Invalid input: range = %d->%d and donor_range = %d->%d",
05925 range[i], range[i+index_dim], donor_range[j], donor_range[j+index_dim]);
05926 return CG_ERROR;
05927 }
05928 }
05929 }
05930
05931
05932 for (index=0; index<zconn->n1to1; index++) {
05933 if (strcmp(connectname, zconn->one21[index].name)==0) {
05934
05935
05936 if (cg->mode==CG_MODE_WRITE) {
05937 cgi_error("Duplicate child name found: %s",connectname);
05938 return CG_ERROR;
05939 }
05940
05941
05942
05943 if (cgi_delete_node(zconn->id, zconn->one21[index].id))
05944 return CG_ERROR;
05945
05946 one21 = &(zconn->one21[index]);
05947
05948 cgi_free_1to1(one21);
05949 break;
05950 }
05951 }
05952
05953 if (index==zconn->n1to1) {
05954 if (zconn->n1to1 == 0) {
05955 zconn->one21 = CGNS_NEW(cgns_1to1, zconn->n1to1+1);
05956 } else {
05957 zconn->one21 = CGNS_RENEW(cgns_1to1, zconn->n1to1+1, zconn->one21);
05958 }
05959 one21 = &(zconn->one21[zconn->n1to1]);
05960 zconn->n1to1++;
05961 }
05962 (*I) = index+1;
05963
05964
05965 if ((one21->transform = (int *)malloc(index_dim*sizeof(int)))==NULL) {
05966 cgi_error("Error allocating memory in cg_1to1_write");
05967 return CG_ERROR;
05968 }
05969
05970
05971 strcpy(one21->name,connectname);
05972 one21->ptset.type = PointRange;
05973 strcpy(one21->ptset.data_type,"I4");
05974 one21->ptset.npts = 2;
05975
05976
05977 strcpy(one21->donor,donorname);
05978 one21->dptset.type = PointRangeDonor;
05979 strcpy(one21->dptset.data_type,"I4");
05980 one21->dptset.npts = 2;
05981
05982
05983 memcpy((void *)one21->transform, (void *)transform, index_dim*sizeof(int));
05984
05985
05986 one21->ptset.id=0;
05987 one21->ptset.link=0;
05988 one21->dptset.id=0;
05989 one21->dptset.link=0;
05990 one21->id = 0;
05991 one21->link=0;
05992 one21->ndescr=0;
05993 one21->ordinal=0;
05994 one21->nuser_data=0;
05995 one21->cprop = 0;
05996
05997
05998 if (zconn->id==0) {
05999 if (cgi_new_node(zone->id, "ZoneGridConnectivity", "ZoneGridConnectivity_t",
06000 &zconn->id, "MT", 0, 0, 0)) return CG_ERROR;
06001 }
06002
06003
06004 length = strlen(one21->donor);
06005 if (cgi_new_node(zconn->id, one21->name, "GridConnectivity1to1_t",
06006 &one21->id, "C1", 1, &length, one21->donor)) return CG_ERROR;
06007
06008
06009 if (cgi_new_node(one21->id, "Transform", "\"int[IndexDimension]\"", &T_id,
06010 "I4", 1, &index_dim, (void *)one21->transform)) return CG_ERROR;
06011
06012
06013 if (cgi_write_ptset(one21->id, "PointRange", &one21->ptset, index_dim,
06014 (void *)range)) return CG_ERROR;
06015
06016
06017 if (cgi_write_ptset(one21->id, "PointRangeDonor", &one21->dptset, index_dim,
06018 (void *)donor_range)) return CG_ERROR;
06019
06020 return CG_OK;
06021 }
06022
06023 int cg_1to1_average_write(int file_number, int B, int Z, int I,
06024 AverageInterfaceType_t AverageInterfaceType)
06025 {
06026 cgns_cprop *cprop;
06027 cgns_caverage *caverage;
06028 cgns_1to1 *one21;
06029 int length;
06030 double dummy_id;
06031
06032
06033 if (AverageInterfaceType<0 || AverageInterfaceType>=NofValidAverageInterfaceTypes) {
06034 cgi_error("Invalid AverageInterfaceType: %d",AverageInterfaceType);
06035 return CG_ERROR;
06036 }
06037
06038
06039 cg = cgi_get_file(file_number);
06040 if (cg == 0) return CG_ERROR;
06041
06042 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
06043
06044
06045 one21 = cgi_get_1to1(cg, B, Z, I);
06046 if (one21 == 0) return CG_ERROR;
06047
06048
06049 if (one21->cprop == 0) {
06050 one21->cprop = CGNS_NEW(cgns_cprop, 1);
06051 cprop = one21->cprop;
06052 strcpy(cprop->name,"GridConnectivityProperty");
06053 cprop->id=0;
06054 cprop->link=0;
06055 cprop->ndescr=0;
06056 cprop->nuser_data=0;
06057 cprop->cperio=0;
06058 cprop->caverage=0;
06059 } else cprop = one21->cprop;
06060
06061
06062 if (cprop->caverage) {
06063
06064 if (cg->mode==CG_MODE_WRITE) {
06065 cgi_error("AverageInterface_t already defined under GridConnectivityProperty_t");
06066 return CG_ERROR;
06067 }
06068
06069
06070 else if (cg->mode==CG_MODE_MODIFY) {
06071
06072 if (cgi_delete_node(cprop->id, cprop->caverage->id))
06073 return CG_ERROR;
06074 cgi_free_caverage(cprop->caverage);
06075 }
06076 } else cprop->caverage = CGNS_NEW(cgns_caverage, 1);
06077 caverage = cprop->caverage;
06078
06079
06080 caverage->type = AverageInterfaceType;
06081
06082
06083 strcpy(caverage->name,"AverageInterface");
06084 caverage->id = 0;
06085 caverage->link = 0;
06086 caverage->ndescr = 0;
06087 caverage->nuser_data = 0;
06088
06089
06090 if (cprop->id==0) {
06091 if (cgi_new_node(one21->id, "GridConnectivityProperty",
06092 "GridConnectivityProperty_t", &cprop->id, "MT", 0, 0, 0))
06093 return CG_ERROR;
06094 }
06095
06096 if (cgi_new_node(cprop->id, "AverageInterface", "AverageInterface_t",
06097 &caverage->id, "MT", 0, 0, 0)) return CG_ERROR;
06098
06099
06100 length = strlen(AverageInterfaceTypeName[caverage->type]);
06101 if (cgi_new_node(caverage->id, "AverageInterfaceType", "AverageInterfaceType_t", &dummy_id,
06102 "C1", 1, &length, (void *)AverageInterfaceTypeName[caverage->type]))
06103 return CG_ERROR;
06104 return CG_OK;
06105 }
06106
06107 int cg_1to1_periodic_write(int file_number, int B, int Z, int I,
06108 float const *RotationCenter, float const *RotationAngle,
06109 float const *Translation)
06110 {
06111 cgns_base *base;
06112 cgns_1to1 *one21;
06113 cgns_cprop *cprop;
06114 cgns_cperio *cperio;
06115 int n;
06116
06117
06118 cg = cgi_get_file(file_number);
06119 if (cg == 0) return CG_ERROR;
06120
06121 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
06122
06123
06124 base = cgi_get_base(cg, B);
06125 if (base==0) return CG_ERROR;
06126
06127
06128 one21 = cgi_get_1to1(cg, B, Z, I);
06129 if (one21 == 0) return CG_ERROR;
06130
06131
06132 if (one21->cprop == 0) {
06133 one21->cprop = CGNS_NEW(cgns_cprop, 1);
06134 cprop = one21->cprop;
06135 strcpy(cprop->name,"GridConnectivityProperty");
06136 cprop->id=0;
06137 cprop->link=0;
06138 cprop->ndescr=0;
06139 cprop->nuser_data=0;
06140 cprop->cperio=0;
06141 cprop->caverage=0;
06142 } else cprop = one21->cprop;
06143
06144
06145 if (cprop->cperio) {
06146
06147 if (cg->mode==CG_MODE_WRITE) {
06148 cgi_error("Periodic_t already defined under GridConnectivityProperty_t.");
06149 return CG_ERROR;
06150 }
06151
06152
06153 else if (cg->mode==CG_MODE_MODIFY) {
06154
06155 if (cgi_delete_node(cprop->id, cprop->cperio->id))
06156 return CG_ERROR;
06157 cgi_free_cperio(cprop->cperio);
06158 }
06159 } else cprop->cperio = CGNS_NEW(cgns_cperio, 1);
06160 cperio = cprop->cperio;
06161
06162
06163 strcpy(cperio->name,"Periodic");
06164 cperio->id = 0;
06165 cperio->link = 0;
06166 cperio->ndescr = 0;
06167 cperio->nuser_data = 0;
06168 cperio->narrays = 3;
06169 cperio->data_class=DataClassNull;
06170 cperio->units=0;
06171
06172
06173 cperio->array = CGNS_NEW(cgns_array, 3);
06174
06175 for (n=0; n<cperio->narrays; n++) {
06176 strcpy(cperio->array[n].data_type, "R4");
06177 cperio->array[n].data = (void *)malloc(base->phys_dim*sizeof(float));
06178 if (cperio->array[n].data == NULL) {
06179 cgi_error("Error allocating cperio->array[n].data");
06180 return CG_ERROR;
06181 }
06182 cperio->array[n].data_dim=1;
06183 cperio->array[n].dim_vals[0]=base->phys_dim;
06184 cperio->array[n].id=0;
06185 cperio->array[n].link=0;
06186 cperio->array[n].ndescr=0;
06187 cperio->array[n].data_class=DataClassNull;
06188 cperio->array[n].units=0;
06189 cperio->array[n].exponents=0;
06190 cperio->array[n].convert=0;
06191 }
06192 memcpy(cperio->array[0].data,RotationCenter,base->phys_dim*sizeof(float));
06193 memcpy(cperio->array[1].data,RotationAngle,base->phys_dim*sizeof(float));
06194 memcpy(cperio->array[2].data,Translation,base->phys_dim*sizeof(float));
06195 strcpy(cperio->array[0].name,"RotationCenter");
06196 strcpy(cperio->array[1].name,"RotationAngle");
06197 strcpy(cperio->array[2].name,"Translation");
06198
06199
06200 if (cprop->id==0) {
06201 if (cgi_new_node(one21->id, "GridConnectivityProperty",
06202 "GridConnectivityProperty_t", &cprop->id, "MT", 0, 0, 0))
06203 return CG_ERROR;
06204 }
06205
06206 if (cgi_new_node(cprop->id, "Periodic", "Periodic_t",
06207 &cperio->id, "MT", 0, 0, 0)) return CG_ERROR;
06208
06209
06210 for (n=0; n<cperio->narrays; n++)
06211 if (cgi_write_array(cperio->id, &cperio->array[n])) return CG_ERROR;
06212 return CG_OK;
06213 }
06214
06215 int cg_boco_write(int file_number, int B, int Z, char const * boconame, BCType_t bocotype,
06216 PointSetType_t ptset_type, int npnts, int const * pnts, int *BC) {
06217 cgns_zone *zone;
06218 cgns_zboco *zboco;
06219 cgns_boco *boco = NULL;
06220 int index, i, index_dim, length;
06221
06222
06223 #if 0
06224 if (ptset_type!= PointList && ptset_type!=PointRange) {
06225 cgi_error("Invalid point set type: %d...?",ptset_type);
06226 return CG_ERROR;
06227 }
06228 if (!(ptset_type==PointRange && npnts==2) && !(ptset_type==PointList && npnts>0)) {
06229 cgi_error("Invalid input: npoint=%d, point set type=%s",
06230 npnts, PointSetTypeName[ptset_type]);
06231 return CG_ERROR;
06232 }
06233 #else
06234 if (ptset_type == PointList || ptset_type == ElementList) {
06235 if (npnts <= 0) {
06236 cgi_error("Invalid input: npoint=%d, point set type=%s",
06237 npnts, PointSetTypeName[ptset_type]);
06238 return CG_ERROR;
06239 }
06240 } else if (ptset_type == PointRange || ptset_type == ElementRange) {
06241 if (npnts != 2) {
06242 cgi_error("Invalid input: npoint=%d, point set type=%s",
06243 npnts, PointSetTypeName[ptset_type]);
06244 return CG_ERROR;
06245 }
06246 } else {
06247 cgi_error("Invalid point set type: %d...?",ptset_type);
06248 return CG_ERROR;
06249 }
06250 #endif
06251 if (bocotype<0 || bocotype>=NofValidBCTypes) {
06252 cgi_error("Invalid BCType: %d",bocotype);
06253 return CG_ERROR;
06254 }
06255 if (cgi_check_strlen(boconame)) return CG_ERROR;
06256
06257
06258 cg = cgi_get_file(file_number);
06259 if (cg == 0) return CG_ERROR;
06260
06261 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
06262
06263
06264 zone = cgi_get_zone(cg, B, Z);
06265 if (zone==0) return CG_ERROR;
06266
06267
06268 if (zone->zboco == 0) {
06269 zone->zboco = CGNS_NEW(cgns_zboco, 1);
06270 zboco = zone->zboco;
06271 strcpy(zboco->name,"ZoneBC");
06272 zboco->id=0;
06273 zboco->link=0;
06274 zboco->ndescr=0;
06275 zboco->nbocos=0;
06276 zboco->state=0;
06277 zboco->data_class=DataClassNull;
06278 zboco->units=0;
06279 zboco->nuser_data=0;
06280 } else zboco = zone->zboco;
06281
06282
06283 index_dim = zone->index_dim;
06284 #if 0
06285 if (ptset_type==PointRange) {
06286 for (i=0; i<index_dim; i++) {
06287 if (pnts[i]<=0 || pnts[i+index_dim]>zone->nijk[i]) {
06288 cgi_error("Invalid input range: %d->%d",pnts[i], pnts[i+index_dim]);
06289 return CG_ERROR;
06290 }
06291 }
06292 }
06293 #endif
06294
06295
06296 for (index=0; index<zboco->nbocos; index++) {
06297 if (strcmp(boconame, zboco->boco[index].name)==0) {
06298
06299
06300 if (cg->mode==CG_MODE_WRITE) {
06301 cgi_error("Duplicate child name found: %s",boconame);
06302 return CG_ERROR;
06303 }
06304
06305
06306
06307 if (cgi_delete_node(zboco->id, zboco->boco[index].id))
06308 return CG_ERROR;
06309
06310 boco = &(zboco->boco[index]);
06311 cgi_free_boco(boco);
06312 break;
06313 }
06314 }
06315
06316 if (index==zboco->nbocos) {
06317 if (zboco->nbocos == 0) {
06318 zboco->boco = CGNS_NEW(cgns_boco, zboco->nbocos+1);
06319 } else {
06320 zboco->boco = CGNS_RENEW(cgns_boco, zboco->nbocos+1, zboco->boco);
06321 }
06322 boco = &(zboco->boco[zboco->nbocos]);
06323 zboco->nbocos++;
06324 }
06325 (*BC) = index+1;
06326
06327
06328 strcpy(boco->name,boconame);
06329 boco->type = bocotype;
06330 boco->ptset = CGNS_NEW(cgns_ptset,1);
06331 boco->ptset->type = ptset_type;
06332 strcpy(boco->ptset->data_type,"I4");
06333 boco->ptset->npts = npnts;
06334
06335
06336 #if 0
06337 if (ptset_type==PointList) boco->ptset->size_of_patch=npnts;
06338 else if (ptset_type==PointRange) {
06339 boco->ptset->size_of_patch = 1;
06340 for (i=0; i<index_dim; i++)
06341 boco->ptset->size_of_patch = boco->ptset->size_of_patch * (pnts[i+index_dim]-pnts[i]+1);
06342 }
06343 #else
06344 if (ptset_type == PointList || ptset_type == ElementList)
06345 boco->ptset->size_of_patch=npnts;
06346 else {
06347 boco->ptset->size_of_patch = 1;
06348 for (i=0; i<index_dim; i++)
06349 boco->ptset->size_of_patch = boco->ptset->size_of_patch * (pnts[i+index_dim]-pnts[i]+1);
06350 }
06351 #endif
06352
06353
06354 boco->normal = 0;
06355 boco->Nindex = 0;
06356 boco->id=0;
06357 boco->link = 0;
06358 boco->location = Vertex;
06359 boco->ptset->id = 0;
06360 boco->ptset->link = 0;
06361 boco->ndescr = 0;
06362 boco->ndataset = 0;
06363 boco->state = 0;
06364 boco->data_class = DataClassNull;
06365 boco->units = 0;
06366 boco->ordinal = 0;
06367 boco->family_name[0]='\0';
06368 boco->nuser_data = 0;
06369 boco->bprop = 0;
06370
06371
06372 if (zboco->id==0) {
06373 if (cgi_new_node(zone->id, "ZoneBC", "ZoneBC_t",
06374 &zboco->id, "MT", 0, 0, 0)) return CG_ERROR;
06375 }
06376
06377 length = strlen(BCTypeName[boco->type]);
06378 if (cgi_new_node(zboco->id, boco->name, "BC_t", &boco->id, "C1", 1,
06379 &length, BCTypeName[boco->type])) return CG_ERROR;
06380
06381
06382 if (npnts>0) {
06383 char_33 PointSetName;
06384 strcpy(PointSetName, PointSetTypeName[boco->ptset->type]);
06385 if (cgi_write_ptset(boco->id, PointSetName, boco->ptset, index_dim,
06386 (void *)pnts)) return CG_ERROR;
06387 }
06388
06389 return CG_OK;
06390 }
06391
06392 int cg_boco_normal_write(int file_number, int B, int Z, int BC, int const * NormalIndex,
06393 int NormalListFlag, DataType_t NormalDataType, void const * NormalList) {
06394 cgns_boco *boco;
06395 int npnts, n, index_dim, phys_dim;
06396
06397
06398 cg = cgi_get_file(file_number);
06399 if (cg == 0) return CG_ERROR;
06400
06401 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
06402
06403 boco = cgi_get_boco(cg, B, Z, BC);
06404 if (boco==0) return CG_ERROR;
06405 npnts = boco->ptset->size_of_patch;
06406
06407 phys_dim=cg->base[B-1].phys_dim;
06408
06409 if (NormalListFlag && npnts) {
06410 cgns_array *normal;
06411
06412 if (boco->normal) {
06413 if (cg->mode==CG_MODE_WRITE) {
06414 cgi_error("InwardNormalList is already defined under BC_t '%s'",
06415 boco->name);
06416 return CG_ERROR;
06417 }
06418 if (cgi_delete_node(boco->id, boco->normal->id))
06419 return CG_ERROR;
06420 cgi_free_array(boco->normal);
06421 } else
06422 boco->normal = CGNS_NEW(cgns_array, 1);
06423 normal = boco->normal;
06424
06425 strcpy(normal->data_type, cgi_adf_datatype(NormalDataType));
06426 normal->data = (void *)malloc(npnts*phys_dim*size_of(normal->data_type));
06427 if (!normal->data) {
06428 cgi_error("Error allocating normal->data");
06429 return CG_ERROR;
06430 }
06431 memcpy(normal->data, NormalList, npnts*phys_dim*size_of(normal->data_type));
06432 strcpy(normal->name, "InwardNormalList");
06433 normal->data_dim =2;
06434 normal->dim_vals[0]=phys_dim;
06435 normal->dim_vals[1]=npnts;
06436
06437
06438 normal->id=0;
06439 normal->link=0;
06440 normal->ndescr=0;
06441 normal->data_class=DataClassNull;
06442 normal->units=0;
06443 normal->exponents=0;
06444 normal->convert=0;
06445
06446 if (cgi_new_node(boco->id, "InwardNormalList", "IndexArray_t",
06447 &normal->id, normal->data_type, 2, normal->dim_vals,
06448 (void *)normal->data)) return CG_ERROR;
06449 }
06450 if (boco->Nindex) {
06451 if (cg->mode==CG_MODE_WRITE) {
06452 cgi_error("InwardNormalIndex is already defined under BC_t '%s'",
06453 boco->name);
06454 return CG_ERROR;
06455 } else {
06456 if (cgi_delete_node(boco->id, boco->index_id))
06457 return CG_ERROR;
06458 free(boco->Nindex);
06459 boco->Nindex = 0;
06460 }
06461 }
06462 if (NormalIndex && cg->base[B-1].zone[Z-1].type == Structured) {
06463 index_dim=cg->base[B-1].zone[Z-1].index_dim;
06464 boco->Nindex = CGNS_NEW(int, index_dim);
06465 for (n=0; n<index_dim; n++)
06466 boco->Nindex[n]=NormalIndex[n];
06467
06468 if (cgi_new_node(boco->id, "InwardNormalIndex", "\"int[IndexDimension]\"",
06469 &boco->index_id, "I4", 1, &index_dim, (void *)NormalIndex))
06470 return CG_ERROR;
06471 }
06472 return CG_OK;
06473 }
06474
06475 int cg_dataset_write(int file_number, int B, int Z, int BC, char const * name,
06476 BCType_t BCType, int *Dset) {
06477
06478 cgns_boco *boco;
06479 cgns_dataset *dataset = NULL;
06480 int index, length;
06481
06482
06483 if (BCType<0 || BCType>=NofValidBCTypes) {
06484 cgi_error("Invalid BCType: %d",BCType);
06485 return CG_ERROR;
06486 }
06487 if (cgi_check_strlen(name)) return CG_ERROR;
06488
06489
06490 cg = cgi_get_file(file_number);
06491 if (cg == 0) return CG_ERROR;
06492
06493 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
06494
06495 boco = cgi_get_boco(cg, B, Z, BC);
06496 if (boco==0) return CG_ERROR;
06497
06498
06499 for (index=0; index<boco->ndataset; index++) {
06500 if (strcmp(name, boco->dataset[index].name)==0) {
06501
06502
06503 if (cg->mode==CG_MODE_WRITE) {
06504 cgi_error("Duplicate child name found: %s",name);
06505 return CG_ERROR;
06506 }
06507
06508
06509
06510 if (cgi_delete_node(boco->id, boco->dataset[index].id))
06511 return CG_ERROR;
06512
06513 dataset = &(boco->dataset[index]);
06514
06515 cgi_free_dataset(dataset);
06516 break;
06517 }
06518 }
06519
06520 if (index==boco->ndataset) {
06521 if (boco->ndataset == 0)
06522 boco->dataset = CGNS_NEW(cgns_dataset, boco->ndataset+1);
06523 else
06524 boco->dataset= CGNS_RENEW(cgns_dataset, boco->ndataset+1, boco->dataset);
06525 dataset= &boco->dataset[boco->ndataset];
06526 boco->ndataset++;
06527 }
06528 (*Dset) = index+1;
06529
06530
06531 dataset->type = BCType;
06532 strcpy(dataset->name, name);
06533
06534
06535 dataset->id = 0;
06536 dataset->link=0;
06537 dataset->ndescr=0;
06538 dataset->dirichlet=0;
06539 dataset->neumann=0;
06540 dataset->state=0;
06541 dataset->data_class=DataClassNull;
06542 dataset->units=0;
06543 dataset->nuser_data=0;
06544
06545
06546
06547 dataset->location = Vertex;
06548 dataset->ptset = 0;
06549
06550
06551 length = strlen(BCTypeName[dataset->type]);
06552 if (cgi_new_node(boco->id, dataset->name, "BCDataSet_t", &dataset->id,
06553 "C1", 1, &length, (void *)BCTypeName[dataset->type])) return CG_ERROR;
06554 return CG_OK;
06555 }
06556
06557 int cg_bcdata_write(int file_number, int B, int Z, int BC, int Dset,
06558 BCDataType_t BCDataType) {
06559
06560 cgns_dataset *dataset;
06561 cgns_bcdata *bcdata;
06562
06563
06564 if (BCDataType<0 || BCDataType>=NofValidBCDataTypes) {
06565 cgi_error("BCDataType %d not valid",BCDataType);
06566 return CG_ERROR;
06567 }
06568
06569
06570 cg = cgi_get_file(file_number);
06571 if (cg == 0) return CG_ERROR;
06572
06573 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
06574
06575 dataset = cgi_get_dataset(cg, B, Z, BC, Dset);
06576 if (dataset==0) return CG_ERROR;
06577
06578 if (BCDataType==Dirichlet) {
06579 if (dataset->dirichlet) {
06580 if (cg->mode == CG_MODE_WRITE) {
06581 cgi_error("Dirichlet data already defined under BCDataSet_t '%s'",
06582 dataset->name);
06583 return CG_ERROR;
06584 }
06585 if (cgi_delete_node(dataset->id, dataset->dirichlet->id))
06586 return CG_ERROR;
06587 cgi_free_bcdata(dataset->dirichlet);
06588 } else
06589 dataset->dirichlet = CGNS_NEW(cgns_bcdata,1);
06590 strcpy(dataset->dirichlet->name, "DirichletData");
06591 bcdata = dataset->dirichlet;
06592 } else {
06593 if (dataset->neumann) {
06594 if (cg->mode == CG_MODE_WRITE) {
06595 cgi_error("Neumann data already defined under BCDataSet_t '%s'",
06596 dataset->name);
06597 return CG_ERROR;
06598 }
06599 if (cgi_delete_node(dataset->id, dataset->neumann->id))
06600 return CG_ERROR;
06601 cgi_free_bcdata(dataset->neumann);
06602 } else
06603 dataset->neumann = CGNS_NEW(cgns_bcdata,1);
06604 strcpy(dataset->neumann->name, "NeumannData");
06605 bcdata = dataset->neumann;
06606 }
06607
06608
06609 bcdata->id = 0;
06610 bcdata->link=0;
06611 bcdata->ndescr=0;
06612 bcdata->data_class=DataClassNull;
06613 bcdata->units=0;
06614 bcdata->narrays=0;
06615 bcdata->nuser_data=0;
06616
06617 if (cgi_new_node(dataset->id, bcdata->name, "BCData_t", &bcdata->id,
06618 "MT", 0, 0, 0)) return CG_ERROR;
06619 return CG_OK;
06620 }
06621
06622 int cg_bc_wallfunction_write(int file_number, int B, int Z, int BC,
06623 WallFunctionType_t WallFunctionType) {
06624
06625 cgns_bprop *bprop;
06626 cgns_bcwall *bcwall;
06627 cgns_boco *boco;
06628 int length;
06629 double dummy_id;
06630
06631
06632 if (WallFunctionType<0 || WallFunctionType>=NofValidWallFunctionTypes) {
06633 cgi_error("Invalid WallFunctionType: %d",WallFunctionType);
06634 return CG_ERROR;
06635 }
06636
06637
06638 cg = cgi_get_file(file_number);
06639 if (cg == 0) return CG_ERROR;
06640
06641 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
06642
06643
06644 boco = cgi_get_boco(cg, B, Z, BC);
06645 if (boco==0) return CG_ERROR;
06646
06647
06648 if (boco->bprop == 0) {
06649 boco->bprop = CGNS_NEW(cgns_bprop, 1);
06650 bprop = boco->bprop;
06651 strcpy(bprop->name,"BCProperty");
06652 bprop->id=0;
06653 bprop->link=0;
06654 bprop->ndescr=0;
06655 bprop->nuser_data=0;
06656 bprop->bcarea=0;
06657 bprop->bcwall=0;
06658 } else bprop = boco->bprop;
06659
06660
06661 if (bprop->bcwall) {
06662
06663 if (cg->mode==CG_MODE_WRITE) {
06664 cgi_error("WallFunction_t already defined under BCProperty_t.");
06665 return CG_ERROR;
06666 }
06667
06668
06669
06670 if (cgi_delete_node(bprop->id, bprop->bcwall->id))
06671 return CG_ERROR;
06672 cgi_free_bcwall(bprop->bcwall);
06673 } else
06674 bprop->bcwall = CGNS_NEW(cgns_bcwall, 1);
06675 bcwall = bprop->bcwall;
06676
06677
06678 bcwall->type = WallFunctionType;
06679
06680
06681 strcpy(bcwall->name,"WallFunction");
06682 bcwall->id = 0;
06683 bcwall->link = 0;
06684 bcwall->ndescr = 0;
06685 bcwall->nuser_data = 0;
06686
06687
06688 if (bprop->id==0) {
06689 if (cgi_new_node(boco->id, "BCProperty", "BCProperty_t",
06690 &bprop->id, "MT", 0, 0, 0)) return CG_ERROR;
06691 }
06692
06693
06694 if (cgi_new_node(bprop->id, "WallFunction", "WallFunction_t",
06695 &bcwall->id, "MT", 0, 0, 0)) return CG_ERROR;
06696
06697
06698 length = strlen(WallFunctionTypeName[bcwall->type]);
06699 if (cgi_new_node(bcwall->id, "WallFunctionType", "WallFunctionType_t", &dummy_id,
06700 "C1", 1, &length, (void *)WallFunctionTypeName[bcwall->type])) return CG_ERROR;
06701
06702 return CG_OK;
06703 }
06704
06705
06706 int cg_bc_area_write(int file_number, int B, int Z, int BC,
06707 AreaType_t AreaType, float SurfaceArea, char const *RegionName) {
06708 cgns_boco *boco;
06709 cgns_bprop *bprop;
06710 cgns_bcarea *bcarea;
06711 int n, len;
06712 char *RegionName32;
06713 double dummy_id;
06714
06715
06716 if (AreaType<0 || AreaType>=NofValidAreaTypes) {
06717 cgi_error("Invalid AreaType: %d",AreaType);
06718 return CG_ERROR;
06719 }
06720
06721
06722 cg = cgi_get_file(file_number);
06723 if (cg == 0) return CG_ERROR;
06724
06725 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
06726
06727
06728 boco = cgi_get_boco(cg, B, Z, BC);
06729 if (boco==0) return CG_ERROR;
06730
06731
06732 if (boco->bprop == 0) {
06733 boco->bprop = CGNS_NEW(cgns_bprop, 1);
06734 bprop = boco->bprop;
06735 strcpy(bprop->name,"BCProperty");
06736 bprop->id=0;
06737 bprop->link=0;
06738 bprop->ndescr=0;
06739 bprop->nuser_data=0;
06740 bprop->bcarea=0;
06741 bprop->bcwall=0;
06742 } else bprop = boco->bprop;
06743
06744
06745 if (bprop->bcarea) {
06746
06747 if (cg->mode==CG_MODE_WRITE) {
06748 cgi_error("Area_t already defined under BCProperty_t.");
06749 return CG_ERROR;
06750 }
06751
06752
06753
06754 if (cgi_delete_node(bprop->id, bprop->bcarea->id))
06755 return CG_ERROR;
06756 cgi_free_bcarea(bprop->bcarea);
06757 } else
06758 bprop->bcarea = CGNS_NEW(cgns_bcarea, 1);
06759 bcarea = bprop->bcarea;
06760
06761
06762 bcarea->type = AreaType;
06763
06764 strcpy(bcarea->name,"Area");
06765 bcarea->id = 0;
06766 bcarea->link = 0;
06767 bcarea->ndescr = 0;
06768 bcarea->nuser_data = 0;
06769 bcarea->narrays = 2;
06770
06771
06772 bcarea->array = CGNS_NEW(cgns_array, 2);
06773
06774 strcpy(bcarea->array[0].data_type, "R4");
06775 bcarea->array[0].data = (void *)malloc(sizeof(float));
06776 if (!bcarea->array[0].data) {
06777 cgi_error("Error allocating bcarea->array[0].data");
06778 return CG_ERROR;
06779 }
06780 memcpy(bcarea->array[0].data, &SurfaceArea, sizeof(float));
06781
06782 strcpy(bcarea->array[0].name, "SurfaceArea");
06783 bcarea->array[0].data_dim=1;
06784 bcarea->array[0].dim_vals[0]=1;
06785
06786 strcpy(bcarea->array[1].data_type, "C1");
06787 bcarea->array[1].data = (void *)malloc(32*sizeof(char));
06788 if (!bcarea->array[1].data) {
06789 cgi_error("Error allocating bcarea->array[1].data");
06790 return CG_ERROR;
06791 }
06792
06793
06794 RegionName32 = (char *)bcarea->array[1].data;
06795 len = strlen(RegionName);
06796 for (n=0; n<len; n++) RegionName32[n]=RegionName[n];
06797 for (n=len; n<32; n++) RegionName32[n]=' ';
06798
06799 strcpy(bcarea->array[1].name, "RegionName");
06800 bcarea->array[1].data_dim=1;
06801 bcarea->array[1].dim_vals[0]=32;
06802
06803
06804 for (n=0; n<bcarea->narrays; n++) {
06805 bcarea->array[n].id=0;
06806 bcarea->array[n].link=0;
06807 bcarea->array[n].ndescr=0;
06808 bcarea->array[n].data_class=DataClassNull;
06809 bcarea->array[n].units=0;
06810 bcarea->array[n].exponents=0;
06811 bcarea->array[n].convert=0;
06812 }
06813
06814
06815 if (bprop->id==0) {
06816 if (cgi_new_node(boco->id, "BCProperty", "BCProperty_t",
06817 &bprop->id, "MT", 0, 0, 0)) return CG_ERROR;
06818 }
06819
06820 if (cgi_new_node(bprop->id, "Area", "Area_t",
06821 &bcarea->id, "MT", 0, 0, 0)) return CG_ERROR;
06822
06823
06824 len = strlen(AreaTypeName[bcarea->type]);
06825 if (cgi_new_node(bcarea->id, "AreaType", "AreaType_t", &dummy_id,
06826 "C1", 1, &len, (void *)AreaTypeName[bcarea->type])) return CG_ERROR;
06827
06828
06829 for (n=0; n<bcarea->narrays; n++)
06830 if (cgi_write_array(bcarea->id, &bcarea->array[n])) return CG_ERROR;
06831
06832 return CG_OK;
06833 }
06834
06835 int cg_rigid_motion_write(int file_number, int B, int Z, char const * rmotionname,
06836 RigidGridMotionType_t type, int *R) {
06837 cgns_zone *zone;
06838 cgns_rmotion *rmotion = NULL;
06839 int index, length;
06840
06841
06842 if (cgi_check_strlen(rmotionname)) return CG_ERROR;
06843
06844 if (type<0 || type >= NofValidRigidGridMotionTypes) {
06845 cgi_error("Invalid input: RigidGridMotionType=%d ?",type);
06846 return CG_ERROR;
06847 }
06848
06849
06850 cg = cgi_get_file(file_number);
06851 if (cg == 0) return CG_ERROR;
06852
06853 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
06854
06855 zone = cgi_get_zone(cg, B, Z);
06856 if (zone==0) return CG_ERROR;
06857
06858
06859 for (index=0; index<zone->nrmotions; index++) {
06860 if (strcmp(rmotionname, zone->rmotion[index].name)==0) {
06861
06862
06863 if (cg->mode==CG_MODE_WRITE) {
06864 cgi_error("Duplicate child name found: %s",rmotionname);
06865 return CG_ERROR;
06866 }
06867
06868
06869
06870 if (cgi_delete_node(zone->id, zone->rmotion[index].id))
06871 return CG_ERROR;
06872
06873 rmotion = &(zone->rmotion[index]);
06874
06875 cgi_free_rmotion(rmotion);
06876 break;
06877 }
06878 }
06879
06880 if (index==zone->nrmotions) {
06881 if (zone->nrmotions == 0) {
06882 zone->rmotion = CGNS_NEW(cgns_rmotion, 1);
06883 } else {
06884 zone->rmotion = CGNS_RENEW(cgns_rmotion, zone->nrmotions+1, zone->rmotion);
06885 }
06886 rmotion = &(zone->rmotion[zone->nrmotions]);
06887 zone->nrmotions++;
06888 }
06889 (*R) = index+1;
06890
06891
06892 strcpy(rmotion->name,rmotionname);
06893 rmotion->type = type;
06894
06895
06896 rmotion->id=0;
06897 rmotion->link=0;
06898 rmotion->ndescr=0;
06899 rmotion->data_class=DataClassNull;
06900 rmotion->units=0;
06901 rmotion->narrays=0;
06902 rmotion->nuser_data=0;
06903
06904
06905 length = strlen(RigidGridMotionTypeName[rmotion->type]);
06906 if (cgi_new_node(zone->id, rmotion->name, "RigidGridMotion_t", &rmotion->id,
06907 "C1", 1, &length, (void *)RigidGridMotionTypeName[rmotion->type])) return CG_ERROR;
06908
06909 return CG_OK;
06910 }
06911
06912 int cg_arbitrary_motion_write(int file_number, int B, int Z, char const * amotionname,
06913 ArbitraryGridMotionType_t type, int *A) {
06914 cgns_zone *zone;
06915 cgns_amotion *amotion = NULL;
06916 int index, length;
06917
06918
06919 if (cgi_check_strlen(amotionname)) return CG_ERROR;
06920
06921 if (type<0 || type >= NofValidArbitraryGridMotionTypes) {
06922 cgi_error("Invalid input: ArbitraryGridMotionType=%d ?",type);
06923 return CG_ERROR;
06924 }
06925
06926
06927 cg = cgi_get_file(file_number);
06928 if (cg == 0) return CG_ERROR;
06929
06930 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
06931
06932 zone = cgi_get_zone(cg, B, Z);
06933 if (zone==0) return CG_ERROR;
06934
06935
06936 for (index=0; index<zone->namotions; index++) {
06937 if (strcmp(amotionname, zone->amotion[index].name)==0) {
06938
06939
06940 if (cg->mode==CG_MODE_WRITE) {
06941 cgi_error("Duplicate child name found: %s",amotionname);
06942 return CG_ERROR;
06943 }
06944
06945
06946
06947 if (cgi_delete_node(zone->id, zone->amotion[index].id))
06948 return CG_ERROR;
06949
06950 amotion = &(zone->amotion[index]);
06951
06952 cgi_free_amotion(amotion);
06953 break;
06954 }
06955 }
06956
06957 if (index==zone->namotions) {
06958 if (zone->namotions == 0) {
06959 zone->amotion = CGNS_NEW(cgns_amotion, 1);
06960 } else {
06961 zone->amotion = CGNS_RENEW(cgns_amotion, zone->namotions+1, zone->amotion);
06962 }
06963 amotion = &(zone->amotion[zone->namotions]);
06964 zone->namotions++;
06965 }
06966 (*A) = index+1;
06967
06968
06969 strcpy(amotion->name,amotionname);
06970 amotion->type = type;
06971
06972
06973 amotion->id=0;
06974 amotion->link=0;
06975 amotion->ndescr=0;
06976 amotion->location=Vertex;
06977 amotion->rind_planes=0;
06978 amotion->narrays=0;
06979 amotion->data_class=DataClassNull;
06980 amotion->units=0;
06981 amotion->nuser_data=0;
06982
06983
06984 length = strlen(ArbitraryGridMotionTypeName[amotion->type]);
06985 if (cgi_new_node(zone->id, amotion->name, "ArbitraryGridMotion_t", &amotion->id,
06986 "C1", 1, &length, (void *)ArbitraryGridMotionTypeName[amotion->type])) return CG_ERROR;
06987 return CG_OK;
06988 }
06989
06990 int cg_simulation_type_write(int file_number, int B, SimulationType_t type) {
06991 cgns_base *base;
06992 int length;
06993
06994
06995 if (type<0 || type >= NofValidSimulationTypes) {
06996 cgi_error("Invalid input: SimulationType=%d ?",type);
06997 return CG_ERROR;
06998 }
06999
07000
07001 cg = cgi_get_file(file_number);
07002 if (cg == 0) return CG_ERROR;
07003
07004 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
07005
07006
07007 base = cgi_get_base(cg, B);
07008 if (base==0) return CG_ERROR;
07009
07010
07011 if (base->type) {
07012 if (cg->mode==CG_MODE_WRITE) {
07013 cgi_error("Simulation type already defined under CGNSBase_t '%s'",
07014 base->name);
07015 return CG_ERROR;
07016 }
07017 if (cgi_delete_node(base->id, base->type_id))
07018 return CG_ERROR;
07019 }
07020 base->type = type;
07021 base->type_id = 0;
07022
07023
07024 length = strlen(SimulationTypeName[type]);
07025 if (cgi_new_node(base->id, "SimulationType", "SimulationType_t", &base->type_id,
07026 "C1", 1, &length, (void *)SimulationTypeName[type])) return CG_ERROR;
07027
07028 return CG_OK;
07029 }
07030
07031 int cg_biter_write(int file_number, int B, char const * bitername, int nsteps) {
07032 cgns_base *base;
07033 cgns_biter *biter;
07034 int length=1;
07035
07036
07037 if (nsteps<=0) {
07038 cgi_error("Invalid input: The number of steps must be a positive integer!");
07039 return CG_ERROR;
07040 }
07041
07042
07043 cg = cgi_get_file(file_number);
07044 if (cg == 0) return CG_ERROR;
07045
07046 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
07047
07048 base = cgi_get_base(cg, B);
07049 if (base==0) return CG_ERROR;
07050
07051
07052 if (base->biter) {
07053 if (cg->mode==CG_MODE_WRITE) {
07054 cgi_error("Error: BaseIterativeData_t already defined");
07055 return CG_ERROR;
07056 }
07057
07058
07059
07060 if (cgi_delete_node(base->id, base->biter->id))
07061 return CG_ERROR;
07062
07063 biter = base->biter;
07064
07065 cgi_free_biter(biter);
07066
07067 } else {
07068 base->biter = CGNS_NEW(cgns_biter, 1);
07069 biter = base->biter;
07070 }
07071
07072
07073 strcpy(biter->name,bitername);
07074 biter->nsteps = nsteps;
07075
07076
07077 biter->id=0;
07078 biter->link=0;
07079 biter->ndescr=0;
07080 biter->narrays=0;
07081 biter->data_class=DataClassNull;
07082 biter->units=0;
07083 biter->nuser_data=0;
07084
07085
07086 if (cgi_new_node(base->id, biter->name, "BaseIterativeData_t", &biter->id,
07087 "I4", 1, &length, (void *)&nsteps)) return CG_ERROR;
07088 return CG_OK;
07089 }
07090
07091 int cg_ziter_write(int file_number, int B, int Z, char const * zitername) {
07092 cgns_zone *zone;
07093 cgns_ziter *ziter;
07094
07095
07096 if (cgi_check_strlen(zitername)) return CG_ERROR;
07097
07098
07099 cg = cgi_get_file(file_number);
07100 if (cg == 0) return CG_ERROR;
07101
07102 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
07103
07104 zone = cgi_get_zone(cg, B, Z);
07105 if (zone==0) return CG_ERROR;
07106
07107
07108 if (zone->ziter) {
07109 if (cg->mode==CG_MODE_WRITE) {
07110 cgi_error("Error: ZoneIterativeData_t already defined");
07111 return CG_ERROR;
07112 }
07113
07114
07115 if (cgi_delete_node(zone->id, zone->ziter->id))
07116 return CG_ERROR;
07117
07118 ziter = zone->ziter;
07119
07120 cgi_free_ziter(ziter);
07121 } else {
07122 zone->ziter = CGNS_NEW(cgns_ziter, 1);
07123 ziter = zone->ziter;
07124 }
07125
07126
07127 strcpy(ziter->name,zitername);
07128
07129
07130 ziter->id=0;
07131 ziter->link=0;
07132 ziter->ndescr=0;
07133 ziter->narrays=0;
07134 ziter->data_class=DataClassNull;
07135 ziter->units=0;
07136 ziter->nuser_data=0;
07137
07138
07139 if (cgi_new_node(zone->id, ziter->name, "ZoneIterativeData_t", &ziter->id,
07140 "MT", 0, 0, 0)) return CG_ERROR;
07141 return CG_OK;
07142 }
07143
07144 int cg_gravity_write(int file_number, int B, float const *gravity_vector) {
07145 cgns_base *base;
07146 cgns_gravity *gravity;
07147
07148
07149 cg = cgi_get_file(file_number);
07150 if (cg == 0) return CG_ERROR;
07151
07152 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
07153
07154
07155 base = cgi_get_base(cg, B);
07156 if (base==0) return CG_ERROR;
07157
07158 if (base->gravity) {
07159 if (cg->mode==CG_MODE_WRITE) {
07160 cgi_error("Gravity is already defined under CGNSBase_t '%s'",
07161 base->name);
07162 return CG_ERROR;
07163 }
07164 if (cgi_delete_node(base->id, base->gravity->id))
07165 return CG_ERROR;
07166 cgi_free_gravity(base->gravity);
07167 } else
07168 base->gravity = CGNS_NEW(cgns_gravity, 1);
07169 gravity = base->gravity;
07170 gravity->vector = CGNS_NEW(cgns_array, 1);
07171
07172
07173 strcpy(gravity->vector->data_type, "R4");
07174 gravity->vector->data = (void *)malloc(base->phys_dim*sizeof(float));
07175 if (!gravity->vector->data) {
07176 cgi_error("Error allocating gravity->vector->data");
07177 return CG_ERROR;
07178 }
07179 memcpy(gravity->vector->data, gravity_vector, base->phys_dim*sizeof(float));
07180 strcpy(gravity->vector->name, "GravityVector");
07181 gravity->vector->data_dim=1;
07182 gravity->vector->dim_vals[0]=base->phys_dim;
07183
07184
07185 gravity->vector->id=0;
07186 gravity->vector->link=0;
07187 gravity->vector->ndescr=0;
07188 gravity->vector->data_class=DataClassNull;
07189 gravity->vector->units=0;
07190 gravity->vector->exponents=0;
07191 gravity->vector->convert=0;
07192
07193
07194 strcpy(gravity->name, "Gravity");
07195 gravity->id=0;
07196 gravity->link=0;
07197 gravity->ndescr=0;
07198 gravity->data_class=DataClassNull;
07199 gravity->units=0;
07200 gravity->nuser_data=0;
07201 gravity->narrays=1;
07202
07203
07204 if (cgi_write_gravity(base->id, gravity)) return CG_ERROR;
07205
07206 return CG_OK;
07207 }
07208
07209 int cg_axisym_write(int file_number, int B, float const *ref_point, float const *axis) {
07210 int n;
07211 cgns_base *base;
07212 cgns_axisym *axisym;
07213
07214
07215 cg = cgi_get_file(file_number);
07216 if (cg == 0) return CG_ERROR;
07217
07218 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
07219
07220
07221 base = cgi_get_base(cg, B);
07222 if (base==0) return CG_ERROR;
07223
07224
07225 if (base->phys_dim != 2) {
07226 cgi_error("Error: Axisymmetry_t can only be specified for bidimensional bases");
07227 return CG_ERROR;
07228 }
07229
07230 if (base->axisym) {
07231 if (cg->mode==CG_MODE_WRITE) {
07232 cgi_error("Axisymmetry is already defined under CGNSBase_t '%s'",
07233 base->name);
07234 return CG_ERROR;
07235 }
07236 if (cgi_delete_node(base->id, base->axisym->id))
07237 return CG_ERROR;
07238 cgi_free_axisym(base->axisym);
07239 } else
07240 base->axisym = CGNS_NEW(cgns_axisym, 1);
07241 axisym = base->axisym;
07242 axisym->array = CGNS_NEW(cgns_array, 2);
07243 axisym->narrays=2;
07244
07245
07246 for (n=0; n<axisym->narrays; n++) {
07247 strcpy(axisym->array[n].data_type, "R4");
07248 axisym->array[n].data = (void *)malloc(base->phys_dim*sizeof(float));
07249 if (!axisym->array[n].data) {
07250 cgi_error("Error allocating axisym->array[n].data");
07251 return CG_ERROR;
07252 }
07253 axisym->array[n].data_dim=1;
07254 axisym->array[n].dim_vals[0]=base->phys_dim;
07255 }
07256 memcpy(axisym->array[0].data, ref_point, base->phys_dim*sizeof(float));
07257 memcpy(axisym->array[1].data, axis, base->phys_dim*sizeof(float));
07258 strcpy(axisym->array[0].name, "AxisymmetryReferencePoint");
07259 strcpy(axisym->array[1].name, "AxisymmetryAxisVector");
07260
07261
07262 for (n=0; n<axisym->narrays; n++) {
07263 axisym->array[n].id=0;
07264 axisym->array[n].link=0;
07265 axisym->array[n].ndescr=0;
07266 axisym->array[n].data_class=DataClassNull;
07267 axisym->array[n].units=0;
07268 axisym->array[n].exponents=0;
07269 axisym->array[n].convert=0;
07270 }
07271
07272
07273 strcpy(axisym->name, "Axisymmetry");
07274 axisym->id=0;
07275 axisym->link=0;
07276 axisym->ndescr=0;
07277 axisym->data_class=DataClassNull;
07278 axisym->units=0;
07279 axisym->nuser_data=0;
07280
07281
07282 if (cgi_write_axisym(base->id, axisym)) return CG_ERROR;
07283
07284 return CG_OK;
07285 }
07286
07287
07288
07289
07290
07291 int cg_famname_write(char const * family_name) {
07292 char *famname;
07293 int ier=0, dim_vals;
07294 double posit_id, dummy_id;
07295
07296
07297 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
07298
07299 if (cgi_check_strlen(family_name)) return CG_ERROR;
07300
07301 famname = cgi_famname_address(CG_MODE_WRITE, &ier);
07302 if (famname==0) return ier;
07303
07304 strcpy(famname, family_name);
07305
07306
07307 if (cgi_posit_id(&posit_id)) return CG_ERROR;
07308 dim_vals = strlen(family_name);
07309 if (cgi_new_node(posit_id, "FamilyName", "FamilyName_t", &dummy_id,
07310 "C1", 1, &dim_vals, (void *)family_name)) return CG_ERROR;
07311
07312 return CG_OK;
07313 }
07314
07315
07316 int cg_convergence_write(int iterations, char const * NormDefinitions) {
07317 cgns_converg *converg;
07318 int ier=0, dim_vals;
07319 double posit_id;
07320
07321
07322 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
07323
07324 converg = cgi_converg_address(CG_MODE_WRITE, &ier);
07325 if (converg==0) return ier;
07326
07327
07328 converg->iterations=0;
07329 converg->id = 0;
07330 converg->link=0;
07331 converg->ndescr=0;
07332 converg->NormDefinitions = 0;
07333 converg->narrays=0;
07334 converg->data_class=DataClassNull;
07335 converg->units=0;
07336 converg->nuser_data=0;
07337
07338
07339 converg->iterations = iterations;
07340 if (NormDefinitions && strlen(NormDefinitions)) {
07341 converg->NormDefinitions=CGNS_NEW(cgns_descr, 1);
07342 converg->NormDefinitions->id=0;
07343 converg->NormDefinitions->link=0;
07344 converg->NormDefinitions->text = CGNS_NEW(char, strlen(NormDefinitions)+1);
07345 strcpy(converg->NormDefinitions->text, NormDefinitions);
07346 strcpy(converg->NormDefinitions->name, "NormDefinitions");
07347 }
07348
07349
07350 if (cgi_posit_id(&posit_id)) return CG_ERROR;
07351 dim_vals=1;
07352 if (cgi_new_node(posit_id, converg->name, "ConvergenceHistory_t", &converg->id,
07353 "I4", 1, &dim_vals, (void *)&converg->iterations)) return CG_ERROR;
07354
07355
07356 if (converg->NormDefinitions &&
07357 cgi_write_descr(converg->id, converg->NormDefinitions)) return CG_ERROR;
07358 return CG_OK;
07359 }
07360
07361 int cg_state_write(char const * StateDescription) {
07362 cgns_state *state;
07363 int ier=0;
07364 double posit_id;
07365
07366
07367 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
07368
07369 state = cgi_state_address(CG_MODE_WRITE, &ier);
07370 if (state==0) return ier;
07371
07372
07373 strcpy(state->name,"ReferenceState");
07374 state->id = 0;
07375 state->link=0;
07376 state->ndescr=0;
07377 state->narrays=0;
07378 state->data_class=DataClassNull;
07379 state->units=0;
07380 state->StateDescription=0;
07381 state->nuser_data=0;
07382
07383
07384 if (StateDescription && strlen(StateDescription)) {
07385 state->StateDescription=CGNS_NEW(cgns_descr, 1);
07386 state->StateDescription->id = 0;
07387 state->StateDescription->link = 0;
07388 state->StateDescription->text = CGNS_NEW(char, strlen(StateDescription)+1);
07389 strcpy(state->StateDescription->text, StateDescription);
07390 strcpy(state->StateDescription->name, "ReferenceStateDescription");
07391 }
07392
07393
07394 if (cgi_posit_id(&posit_id)) return CG_ERROR;
07395
07396
07397 if (cgi_new_node(posit_id, state->name, "ReferenceState_t", &state->id,
07398 "MT", 0, 0, 0)) return CG_ERROR;
07399
07400
07401 if (state->StateDescription &&
07402 cgi_write_descr(state->id, state->StateDescription)) return CG_ERROR;
07403 return CG_OK;
07404 }
07405
07406 int cg_equationset_write(int EquationDimension) {
07407 cgns_equations *equations;
07408 int ier=0;
07409 double posit_id;
07410
07411
07412 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
07413
07414 equations=cgi_equations_address(CG_MODE_WRITE, &ier);
07415 if (equations==0) return ier;
07416
07417
07418 equations->equation_dim=EquationDimension;
07419
07420
07421 strcpy(equations->name, "FlowEquationSet");
07422 equations->id=0;
07423 equations->link=0;
07424 equations->ndescr=0;
07425 equations->governing=0;
07426 equations->gas=0;
07427 equations->visc=0;
07428 equations->conduct=0;
07429 equations->closure=0;
07430 equations->turbulence=0;
07431 equations->relaxation=0;
07432 equations->chemkin=0;
07433 equations->data_class=DataClassNull;
07434 equations->units=0;
07435 equations->nuser_data=0;
07436 equations->elecfield = 0;
07437 equations->magnfield = 0;
07438 equations->emconduct = 0;
07439
07440
07441 if (cgi_posit_id(&posit_id)) return CG_ERROR;
07442 if (cgi_write_equations(posit_id, equations)) return CG_ERROR;
07443 return CG_OK;
07444 }
07445
07446 int cg_governing_write(GoverningEquationsType_t Equationstype) {
07447 cgns_governing *governing;
07448 int ier=0, index_dim, dim_vals;
07449 double posit_id;
07450
07451
07452 if (Equationstype<0 || Equationstype>=NofValidGoverningEquationsTypes) {
07453 cgi_error("Invalid Governing Equations Type: %d",Equationstype);
07454 return CG_ERROR;
07455 }
07456 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
07457
07458 governing = cgi_governing_address(CG_MODE_WRITE, &ier);
07459 if (governing==0) return ier;
07460
07461
07462 governing->type=Equationstype;
07463
07464
07465 strcpy(governing->name, "GoverningEquations");
07466 governing->id=0;
07467 governing->link=0;
07468 governing->ndescr=0;
07469 governing->diffusion_model=0;
07470 governing->nuser_data=0;
07471
07472 if (posit_base && posit_zone) {
07473 index_dim = cg->base[posit_base-1].zone[posit_zone-1].index_dim;
07474
07475
07476 } else if (posit_base) {
07477 index_dim = cg->base[posit_base-1].cell_dim;
07478
07479 } else {
07480 cgi_error("Can't find IndexDimension in cg_governing_write.");
07481 return CG_NO_INDEX_DIM;
07482 }
07483 if (index_dim==1) governing->dim_vals=1;
07484 else if (index_dim==2) governing->dim_vals=3;
07485 else if (index_dim==3) governing->dim_vals=6;
07486
07487
07488 if (cgi_posit_id(&posit_id)) return CG_ERROR;
07489 dim_vals = strlen(GoverningEquationsTypeName[governing->type]);
07490 if (cgi_new_node(posit_id, "GoverningEquations",
07491 "GoverningEquations_t", &governing->id, "C1", 1, &dim_vals,
07492 GoverningEquationsTypeName[governing->type])) return CG_ERROR;
07493 return CG_OK;
07494 }
07495
07496 int cg_diffusion_write(int const * diffusion_model) {
07497 int *diffusion;
07498 int n, ndata, ier=0, index_dim;
07499 double posit_id, dummy_id;
07500
07501
07502 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
07503
07504 diffusion = cgi_diffusion_address(CG_MODE_WRITE, &ier);
07505 if (diffusion==0) return ier;
07506
07507
07508 if (posit_base && posit_zone) {
07509 index_dim = cg->base[posit_base-1].zone[posit_zone-1].index_dim;
07510
07511
07512 } else if (posit_base) {
07513 index_dim = cg->base[posit_base-1].cell_dim;
07514 } else {
07515 cgi_error("Can't find IndexDimension in cg_diffusion_write.");
07516 return CG_NO_INDEX_DIM;
07517 }
07518 if (index_dim==1) ndata=1;
07519 else if (index_dim==2) ndata=3;
07520 else if (index_dim==3) ndata=6;
07521 else {
07522 cgi_error("invalid value for IndexDimension");
07523 return CG_ERROR;
07524 }
07525
07526 for (n=0; n<ndata; n++) diffusion[n] = diffusion_model[n];
07527
07528
07529 if (cgi_posit_id(&posit_id)) return CG_ERROR;
07530
07531
07532 if (cgi_new_node(posit_id, "DiffusionModel",
07533 "\"int[1+...+IndexDimension]\"", &dummy_id, "I4", 1,
07534 &ndata, (void *)diffusion_model)) return CG_ERROR;
07535 return CG_OK;
07536 }
07537
07538 int cg_model_write(char const * ModelLabel, ModelType_t ModelType) {
07539 cgns_model *model;
07540 char ModelName[33];
07541 int ier=0, index_dim;
07542 double posit_id;
07543
07544
07545 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
07546 if (ModelType<0 || ModelType>=NofValidModelTypes) {
07547 cgi_error("Invalid %s Type: %d",ModelLabel,ModelType);
07548 return CG_ERROR;
07549 }
07550
07551
07552 if (strcmp(ModelLabel, "GasModel_t")==0) {
07553 if (ModelType!=ModelTypeNull && ModelType!=ModelTypeUserDefined &&
07554 ModelType!=Ideal && ModelType!=VanderWaals &&
07555 ModelType!=CaloricallyPerfect && ModelType!=ThermallyPerfect &&
07556 ModelType!=ConstantDensity && ModelType!=RedlichKwong) {
07557 cgi_error("Model Type '%s' is not supported for %s",
07558 ModelTypeName[ModelType],ModelLabel);
07559 return CG_ERROR;
07560 }
07561 } else if (strcmp(ModelLabel, "ViscosityModel_t")==0) {
07562 if (ModelType!=ModelTypeNull && ModelType!=ModelTypeUserDefined &&
07563 ModelType!=Constant && ModelType!=PowerLaw && ModelType!=SutherlandLaw) {
07564 cgi_error("Model Type '%s' is not supported for %s",
07565 ModelTypeName[ModelType],ModelLabel);
07566 return CG_ERROR;
07567 }
07568 } else if (strcmp(ModelLabel, "ThermalConductivityModel_t")==0) {
07569 if (ModelType!=ModelTypeNull && ModelType!=ModelTypeUserDefined &&
07570 ModelType!=PowerLaw && ModelType!=SutherlandLaw && ModelType!=ConstantPrandtl) {
07571 cgi_error("Model Type '%s' is not supported for %s",
07572 ModelTypeName[ModelType],ModelLabel);
07573 return CG_ERROR;
07574 }
07575 } else if (strcmp(ModelLabel, "TurbulenceModel_t")==0) {
07576 if (ModelType!=ModelTypeNull && ModelType!=ModelTypeUserDefined &&
07577 ModelType!=Algebraic_BaldwinLomax && ModelType!=Algebraic_CebeciSmith &&
07578 ModelType!=HalfEquation_JohnsonKing && ModelType!=OneEquation_BaldwinBarth &&
07579 ModelType!=OneEquation_SpalartAllmaras && ModelType!=TwoEquation_JonesLaunder &&
07580 ModelType!=TwoEquation_MenterSST && ModelType!=TwoEquation_Wilcox) {
07581 cgi_error("Model Type '%s' is not supported for %s",
07582 ModelTypeName[ModelType],ModelLabel);
07583 return CG_ERROR;
07584 }
07585 } else if (strcmp(ModelLabel, "TurbulenceClosure_t")==0) {
07586 if (ModelType!=ModelTypeNull && ModelType!=ModelTypeUserDefined &&
07587 ModelType!=EddyViscosity && ModelType!=ReynoldsStress &&
07588 ModelType!=ReynoldsStressAlgebraic) {
07589 cgi_error("Model Type '%s' is not supported for %s",
07590 ModelTypeName[ModelType],ModelLabel);
07591 return CG_ERROR;
07592 }
07593 } else if (strcmp(ModelLabel, "ThermalRelaxationModel_t")==0) {
07594 if (ModelType!=ModelTypeNull && ModelType!=ModelTypeUserDefined &&
07595 ModelType!=Frozen && ModelType!=ThermalEquilib &&
07596 ModelType!=ThermalNonequilib) {
07597 cgi_error("Model Type '%s' is not supported for %s",
07598 ModelTypeName[ModelType],ModelLabel);
07599 return CG_ERROR;
07600 }
07601 } else if (strcmp(ModelLabel, "ChemicalKineticsModel_t")==0) {
07602 if (ModelType!=ModelTypeNull && ModelType!=ModelTypeUserDefined &&
07603 ModelType!=Frozen && ModelType!=ChemicalEquilibCurveFit &&
07604 ModelType!=ChemicalEquilibMinimization && ModelType!=ChemicalNonequilib) {
07605 cgi_error("Model Type '%s' is not supported for %s",
07606 ModelTypeName[ModelType],ModelLabel);
07607 return CG_ERROR;
07608 }
07609 }
07610 else if (strcmp(ModelLabel, "EMElectricFieldModel_t")==0) {
07611 if (ModelType!=ModelTypeNull && ModelType!=ModelTypeUserDefined &&
07612 ModelType!=Frozen && ModelType!=Voltage &&
07613 ModelType!=Interpolated && ModelType!=Constant) {
07614 cgi_error("Model Type '%s' is not supported for %s",
07615 ModelTypeName[ModelType],ModelLabel);
07616 return 1;
07617 }
07618 }
07619 else if (strcmp(ModelLabel, "EMMagneticFieldModel_t")==0) {
07620 if (ModelType!=ModelTypeNull && ModelType!=ModelTypeUserDefined &&
07621 ModelType!=Frozen && ModelType!=Interpolated &&
07622 ModelType!=Constant) {
07623 cgi_error("Model Type '%s' is not supported for %s",
07624 ModelTypeName[ModelType],ModelLabel);
07625 return 1;
07626 }
07627 }
07628 else if (strcmp(ModelLabel, "EMConductivityModel_t")==0) {
07629 if (ModelType!=ModelTypeNull && ModelType!=ModelTypeUserDefined &&
07630 ModelType!=Frozen && ModelType!=Constant &&
07631 ModelType!=Equilibrium_LinRessler &&
07632 ModelType!=Chemistry_LinRessler) {
07633 cgi_error("Model Type '%s' is not supported for %s",
07634 ModelTypeName[ModelType],ModelLabel);
07635 return 1;
07636 }
07637 }
07638
07639 if (strcmp(ModelLabel, "ChemicalKineticsModel_t") &&
07640 strcmp(ModelLabel, "ThermalRelaxationModel_t") &&
07641 strcmp(ModelLabel, "TurbulenceClosure_t") &&
07642 strcmp(ModelLabel, "TurbulenceModel_t") &&
07643 strcmp(ModelLabel, "ThermalConductivityModel_t") &&
07644 strcmp(ModelLabel, "ViscosityModel_t") &&
07645 strcmp(ModelLabel, "EMElectricFieldModel_t") &&
07646 strcmp(ModelLabel, "EMMagneticFieldModel_t") &&
07647 strcmp(ModelLabel, "EMConductivityModel_t") &&
07648 strcmp(ModelLabel, "GasModel_t")) {
07649 cgi_error("Invalid Model Label: %s",ModelLabel);
07650 return CG_ERROR;
07651 }
07652
07653
07654 model = cgi_model_address(CG_MODE_WRITE, ModelLabel, &ier);
07655 if (model==0) return ier;
07656
07657
07658 model->type = ModelType;
07659 strcpy(ModelName,ModelLabel);
07660 ModelName[strlen(ModelLabel)-2]='\0';
07661 strcpy(model->name, ModelName);
07662
07663
07664 model->id=0;
07665 model->link=0;
07666 model->ndescr=0;
07667 model->narrays=0;
07668 model->data_class=DataClassNull;
07669 model->units=0;
07670 model->diffusion_model=0;
07671 model->dim_vals=0;
07672 model->nuser_data=0;
07673
07674 if (strcmp(ModelLabel, "TurbulenceModel_t")==0) {
07675 if (posit_base && posit_zone) {
07676 index_dim = cg->base[posit_base-1].zone[posit_zone-1].index_dim;
07677
07678 } else if (posit_base) {
07679 index_dim = cg->base[posit_base-1].cell_dim;
07680 } else {
07681 cgi_error("Can't find IndexDimension in cg_model_write.");
07682 return CG_NO_INDEX_DIM;
07683 }
07684 if (index_dim==1) model->dim_vals=1;
07685 else if (index_dim==2) model->dim_vals=3;
07686 else if (index_dim==3) model->dim_vals=6;
07687 else {
07688 cgi_error("invalid value for IndexDimension");
07689 return CG_ERROR;
07690 }
07691 }
07692
07693
07694 if (cgi_posit_id(&posit_id)) return CG_ERROR;
07695 if (cgi_write_model(posit_id, model)) return CG_ERROR;
07696 return CG_OK;
07697 }
07698
07699 int cg_array_write(char const * ArrayName, DataType_t DataType,
07700 int DataDimension, int const * DimensionVector, void const * Data) {
07701 cgns_array *array;
07702 int n, ier=0;
07703 double posit_id;
07704
07705
07706 if (cgi_check_strlen(ArrayName)) return CG_ERROR;
07707 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
07708 if (DataType!=RealSingle && DataType!=RealDouble &&
07709 DataType!=Integer && DataType!=Character) {
07710 cgi_error("Invalid datatype for data array: %d", DataType);
07711 return CG_ERROR;
07712 }
07713 if (DataDimension>12) {
07714 cgi_error("Data arrays are limited to 12 dimensions");
07715 return CG_ERROR;
07716 }
07717 for (n=0; n<DataDimension; n++) {
07718 if (DimensionVector[n]<=0) {
07719 cgi_error("Invalid array size: %d",DimensionVector[n]);
07720 return CG_ERROR;
07721 }
07722 }
07723
07724
07725 array = cgi_array_address(CG_MODE_WRITE, 0, ArrayName, &ier);
07726
07727
07728 if (array==0) return ier;
07729
07730
07731 strcpy(array->name, ArrayName);
07732 strcpy(array->data_type, cgi_adf_datatype(DataType));
07733 array->data_dim = DataDimension;
07734 for (n=0; n<DataDimension; n++) array->dim_vals[n]=DimensionVector[n];
07735
07736
07737 array->link=0;
07738 array->ndescr=0;
07739 array->data_class=DataClassNull;
07740 array->units=0;
07741 array->exponents=0;
07742 array->convert=0;
07743 array->data=0;
07744
07745
07746 if (cgi_posit_id(&posit_id)) return CG_ERROR;
07747 if (cgi_new_node(posit_id, array->name, "DataArray_t", &array->id,
07748 array->data_type, array->data_dim, array->dim_vals, Data)) return CG_ERROR;
07749
07750 return CG_OK;
07751 }
07752
07753 int cg_integral_write(char const * IntegralDataName) {
07754 cgns_integral *integral;
07755 int ier=0;
07756 double posit_id;
07757
07758
07759 if (cgi_check_strlen(IntegralDataName)) return CG_ERROR;
07760 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
07761
07762 integral = cgi_integral_address(CG_MODE_WRITE, 0, IntegralDataName, &ier);
07763 if (integral==0) return ier;
07764
07765 strcpy(integral->name, IntegralDataName);
07766
07767
07768 integral->id=0;
07769 integral->link=0;
07770 integral->ndescr=0;
07771 integral->narrays=0;
07772 integral->data_class=DataClassNull;
07773 integral->units=0;
07774 integral->nuser_data=0;
07775
07776
07777 if (cgi_posit_id(&posit_id)) return CG_ERROR;
07778 if (cgi_new_node(posit_id, integral->name, "IntegralData_t",
07779 &integral->id, "MT", 0, 0, 0)) return CG_ERROR;
07780 return CG_OK;
07781 }
07782
07783 int cg_rind_write(int const * RindData) {
07784 int n, ier=0;
07785 int *rind, index_dim;
07786 double posit_id;
07787
07788
07789 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
07790
07791 rind = cgi_rind_address(CG_MODE_WRITE, &ier);
07792 if (rind==0) return ier;
07793
07794 if (posit_base && posit_zone) {
07795 index_dim = cg->base[posit_base-1].zone[posit_zone-1].index_dim;
07796 } else {
07797 cgi_error("Can't find IndexDimension in cg_rind_write.");
07798 return CG_NO_INDEX_DIM;
07799 }
07800
07801 for (n=0; n<2*index_dim; n++) rind[n]=RindData[n];
07802
07803
07804 if (cgi_posit_id(&posit_id)) return CG_ERROR;
07805 if (cgi_write_rind(posit_id, rind, index_dim)) return CG_ERROR;
07806 return CG_OK;
07807 }
07808
07809 int cg_descriptor_write(char const * descr_name, char const * descr_text) {
07810 cgns_descr *descr;
07811 int ier=0;
07812 double posit_id;
07813
07814
07815 if (cgi_check_strlen(descr_name)) return CG_ERROR;
07816 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
07817
07818 descr = cgi_descr_address(CG_MODE_WRITE, 0, descr_name, &ier);
07819 if (descr==0) return ier;
07820
07821
07822 strcpy(descr->name, descr_name);
07823 if ((descr->text = (char *)malloc((strlen(descr_text)+1)*sizeof(char)))==NULL) {
07824 cgi_error("Error allocating memory for Descriptor...");
07825 return CG_ERROR;
07826 }
07827 strcpy(descr->text, descr_text);
07828
07829
07830 descr->id=0;
07831 descr->link=0;
07832
07833
07834 if (cgi_posit_id(&posit_id)) return CG_ERROR;
07835 if (cgi_write_descr(posit_id, descr)) return CG_ERROR;
07836 return CG_OK;
07837 }
07838
07839 int cg_units_write(MassUnits_t mass, LengthUnits_t length, TimeUnits_t time,
07840 TemperatureUnits_t temperature, AngleUnits_t angle) {
07841 int ier=0;
07842 cgns_units *units;
07843 double posit_id;
07844
07845
07846 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
07847 if (mass < 0 || mass >= NofValidMassUnits) {
07848 cgi_error("Invalid input: mass unit %d not supported",mass);
07849 return CG_ERROR;
07850 }
07851 if (length < 0 || length >= NofValidLengthUnits) {
07852 cgi_error("Invalid input: length unit %d not supported", length);
07853 return CG_ERROR;
07854 }
07855 if (time < 0 || time >= NofValidTimeUnits) {
07856 cgi_error("Invalid input: time unit %d not supported", time);
07857 return CG_ERROR;
07858 }
07859 if (temperature < 0 || temperature >= NofValidTemperatureUnits) {
07860 cgi_error("Invalid input: temperature unit %d not supported", temperature);
07861 return CG_ERROR;
07862 }
07863 if (angle < 0 || angle >= NofValidAngleUnits) {
07864 cgi_error("Invalid input: angle unit %d not supported", angle);
07865 return CG_ERROR;
07866 }
07867
07868
07869 units = cgi_units_address(CG_MODE_WRITE, &ier);
07870 if (units==0) return ier;
07871
07872
07873 units->mass = mass;
07874 units->length = length;
07875 units->time = time;
07876 units->temperature = temperature;
07877 units->angle = angle;
07878
07879
07880 strcpy(units->name, "DimensionalUnits");
07881 units->id = 0;
07882 units->link=0;
07883 units->nunits = 5;
07884
07885
07886 if (cgi_posit_id(&posit_id)) return CG_ERROR;
07887 if (cgi_write_units(posit_id, units)) return CG_ERROR;
07888 return CG_OK;
07889 }
07890
07891 int cg_unitsfull_write(MassUnits_t mass, LengthUnits_t length,
07892 TimeUnits_t time, TemperatureUnits_t temperature, AngleUnits_t angle,
07893 ElectricCurrentUnits_t current, SubstanceAmountUnits_t amount,
07894 LuminousIntensityUnits_t intensity) {
07895 int ier=0;
07896 cgns_units *units;
07897 double posit_id;
07898
07899
07900 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
07901 if (mass < 0 || mass >= NofValidMassUnits) {
07902 cgi_error("Invalid input: mass unit %d not supported",mass);
07903 return CG_ERROR;
07904 }
07905 if (length < 0 || length >= NofValidLengthUnits) {
07906 cgi_error("Invalid input: length unit %d not supported", length);
07907 return CG_ERROR;
07908 }
07909 if (time < 0 || time >= NofValidTimeUnits) {
07910 cgi_error("Invalid input: time unit %d not supported", time);
07911 return CG_ERROR;
07912 }
07913 if (temperature < 0 || temperature >= NofValidTemperatureUnits) {
07914 cgi_error("Invalid input: temperature unit %d not supported", temperature);
07915 return CG_ERROR;
07916 }
07917 if (angle < 0 || angle >= NofValidAngleUnits) {
07918 cgi_error("Invalid input: angle unit %d not supported", angle);
07919 return CG_ERROR;
07920 }
07921 if (current < 0 || current >= NofValidElectricCurrentUnits) {
07922 cgi_error("Invalid input: electric current unit %d not supported", current);
07923 return CG_ERROR;
07924 }
07925 if (amount < 0 || amount >= NofValidSubstanceAmountUnits) {
07926 cgi_error("Invalid input: substance amount unit %d not supported", amount);
07927 return CG_ERROR;
07928 }
07929 if (intensity < 0 || intensity >= NofValidLuminousIntensityUnits) {
07930 cgi_error("Invalid input: luminous intensity unit %d not supported", intensity);
07931 return CG_ERROR;
07932 }
07933
07934
07935 units = cgi_units_address(CG_MODE_WRITE, &ier);
07936 if (units==0) return ier;
07937
07938
07939 units->mass = mass;
07940 units->length = length;
07941 units->time = time;
07942 units->temperature = temperature;
07943 units->angle = angle;
07944 units->current = current;
07945 units->amount = amount;
07946 units->intensity = intensity;
07947
07948
07949 strcpy(units->name, "DimensionalUnits");
07950 units->id = 0;
07951 units->link=0;
07952 units->nunits = 8;
07953
07954
07955 if (cgi_posit_id(&posit_id)) return CG_ERROR;
07956 if (cgi_write_units(posit_id, units)) return CG_ERROR;
07957 return CG_OK;
07958 }
07959
07960 int cg_exponents_write(DataType_t DataType, void const * exponents) {
07961 cgns_exponent *exponent;
07962 int ier=0;
07963 double posit_id;
07964
07965
07966 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
07967
07968 exponent = cgi_exponent_address(CG_MODE_WRITE, &ier);
07969 if (exponent==0) return ier;
07970
07971
07972 strcpy(exponent->data_type, cgi_adf_datatype(DataType));
07973 exponent->data = (void *)malloc(5*size_of(exponent->data_type));
07974 if (!exponent->data) {
07975 cgi_error("Error allocating exponent->data");
07976 return CG_ERROR;
07977 }
07978
07979 if (DataType==RealSingle) {
07980 (*((float *)exponent->data+0)) = (*((float *) exponents+0));
07981 (*((float *)exponent->data+1)) = (*((float *) exponents+1));
07982 (*((float *)exponent->data+2)) = (*((float *) exponents+2));
07983 (*((float *)exponent->data+3)) = (*((float *) exponents+3));
07984 (*((float *)exponent->data+4)) = (*((float *) exponents+4));
07985
07986 } else if (DataType==RealDouble) {
07987 (*((double *)exponent->data+0)) = (*((double *) exponents+0));
07988 (*((double *)exponent->data+1)) = (*((double *) exponents+1));
07989 (*((double *)exponent->data+2)) = (*((double *) exponents+2));
07990 (*((double *)exponent->data+3)) = (*((double *) exponents+3));
07991 (*((double *)exponent->data+4)) = (*((double *) exponents+4));
07992 }
07993
07994
07995 strcpy(exponent->name, "DimensionalExponents");
07996 exponent->id = 0;
07997 exponent->link = 0;
07998 exponent->nexps = 5;
07999
08000
08001 if (cgi_posit_id(&posit_id)) return CG_ERROR;
08002 if (cgi_write_exponents(posit_id, exponent)) return CG_ERROR;
08003 return CG_OK;
08004 }
08005
08006 int cg_expfull_write(DataType_t DataType, void const * exponents) {
08007 cgns_exponent *exponent;
08008 int ier=0;
08009 double posit_id;
08010
08011
08012 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
08013
08014 exponent = cgi_exponent_address(CG_MODE_WRITE, &ier);
08015 if (exponent==0) return ier;
08016
08017
08018 strcpy(exponent->data_type, cgi_adf_datatype(DataType));
08019 exponent->data = (void *)malloc(8*size_of(exponent->data_type));
08020 if (exponent->data == NULL) {
08021 cgi_error("Error allocating exponent->data");
08022 return CG_ERROR;
08023 }
08024
08025 if (DataType==RealSingle) {
08026 (*((float *)exponent->data+0)) = (*((float *) exponents+0));
08027 (*((float *)exponent->data+1)) = (*((float *) exponents+1));
08028 (*((float *)exponent->data+2)) = (*((float *) exponents+2));
08029 (*((float *)exponent->data+3)) = (*((float *) exponents+3));
08030 (*((float *)exponent->data+4)) = (*((float *) exponents+4));
08031 (*((float *)exponent->data+5)) = (*((float *) exponents+5));
08032 (*((float *)exponent->data+6)) = (*((float *) exponents+6));
08033 (*((float *)exponent->data+7)) = (*((float *) exponents+7));
08034
08035 } else if (DataType==RealDouble) {
08036 (*((double *)exponent->data+0)) = (*((double *) exponents+0));
08037 (*((double *)exponent->data+1)) = (*((double *) exponents+1));
08038 (*((double *)exponent->data+2)) = (*((double *) exponents+2));
08039 (*((double *)exponent->data+3)) = (*((double *) exponents+3));
08040 (*((double *)exponent->data+4)) = (*((double *) exponents+4));
08041 (*((double *)exponent->data+5)) = (*((double *) exponents+5));
08042 (*((double *)exponent->data+6)) = (*((double *) exponents+6));
08043 (*((double *)exponent->data+7)) = (*((double *) exponents+7));
08044 }
08045
08046
08047 strcpy(exponent->name, "DimensionalExponents");
08048 exponent->id = 0;
08049 exponent->link = 0;
08050 exponent->nexps = 8;
08051
08052
08053 if (cgi_posit_id(&posit_id)) return CG_ERROR;
08054 if (cgi_write_exponents(posit_id, exponent)) return CG_ERROR;
08055 return CG_OK;
08056 }
08057
08058 int cg_conversion_write(DataType_t DataType, void const * ConversionFactors) {
08059 cgns_conversion *conversion;
08060 int ier=0, dim_vals=2;
08061 double posit_id;
08062
08063
08064 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
08065
08066 conversion = cgi_conversion_address(CG_MODE_WRITE, &ier);
08067 if (conversion==0) return ier;
08068
08069
08070 strcpy(conversion->data_type, cgi_adf_datatype(DataType));
08071 conversion->data = (void *)malloc(2*size_of(conversion->data_type));
08072 if (!conversion->data) {
08073 cgi_error("Error allocating conversion->data");
08074 return CG_ERROR;
08075 }
08076
08077 if (DataType==RealSingle) {
08078 *((float *) conversion->data+0) = *((float *)ConversionFactors+0);
08079 *((float *) conversion->data+1) = *((float *)ConversionFactors+1);
08080
08081 } else if (DataType==RealDouble) {
08082 *((double *) conversion->data+0) = *((double *)ConversionFactors+0);
08083 *((double *) conversion->data+1) = *((double *)ConversionFactors+1);
08084 }
08085
08086
08087 strcpy(conversion->name, "DataConversion");
08088 conversion->id=0;
08089 conversion->link=0;
08090
08091
08092 if (cgi_posit_id(&posit_id)) return CG_ERROR;
08093 if (cgi_new_node(posit_id, "DataConversion", "DataConversion_t",
08094 &conversion->id, conversion->data_type, 1, &dim_vals,
08095 conversion->data)) return CG_ERROR;
08096 return CG_OK;
08097 }
08098
08099 int cg_dataclass_write(DataClass_t dataclass) {
08100 DataClass_t *DataClass;
08101 int ier=0;
08102 double posit_id;
08103
08104
08105 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
08106
08107 DataClass = cgi_dataclass_address(CG_MODE_WRITE, &ier);
08108 if (DataClass==0) return ier;
08109
08110 (*DataClass) = dataclass;
08111
08112
08113 if (cgi_posit_id(&posit_id)) return CG_ERROR;
08114 if (cgi_write_dataclass(posit_id, dataclass)) return CG_ERROR;
08115 return CG_OK;
08116 }
08117
08118 int cg_gridlocation_write(GridLocation_t GridLocation) {
08119 GridLocation_t *location;
08120 int ier=0, dim_vals;
08121 double posit_id, dummy_id;
08122
08123
08124 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
08125
08126 location = cgi_location_address(CG_MODE_WRITE, &ier);
08127 if (location==0) return ier;
08128
08129 if ((GridLocation == IFaceCenter || GridLocation == JFaceCenter ||
08130 GridLocation == KFaceCenter) &&
08131 cg->base[posit_base-1].zone[posit_zone-1].type != Structured) {
08132 cgi_error("GridLocation [IJK]FaceCenter only valid for Structured Grid");
08133 return CG_ERROR;
08134 }
08135
08136 ier = 0;
08137 if (strcmp(posit->label,"FlowSolution_t")==0 ||
08138 strcmp(posit->label,"DiscreteData_t")== 0 ||
08139 strcmp(posit->label,"ArbitraryGridMotion_t")== 0) {
08140 if (GridLocation != Vertex && GridLocation != CellCenter &&
08141 GridLocation != IFaceCenter && GridLocation != JFaceCenter &&
08142 GridLocation != KFaceCenter) ier = 1;
08143 }
08144 else if (strcmp(posit->label,"OversetHoles_t")==0) {
08145 if (GridLocation != Vertex && GridLocation != CellCenter)
08146 ier = 1;
08147 }
08148 else if (strcmp(posit->label,"GridConnectivity_t")==0) {
08149 if (GridLocation != Vertex && GridLocation != CellCenter &&
08150 GridLocation != FaceCenter && GridLocation != IFaceCenter &&
08151 GridLocation != JFaceCenter && GridLocation != KFaceCenter)
08152 ier = 1;
08153 }
08154 else if (strcmp(posit->label,"BC_t")==0) {
08155 if (GridLocation != Vertex && GridLocation != FaceCenter &&
08156 GridLocation != IFaceCenter && GridLocation != JFaceCenter &&
08157 GridLocation != KFaceCenter)
08158 ier = 1;
08159 }
08160 else {
08161 if (GridLocation < 0 || GridLocation >= NofValidGridLocation)
08162 ier = 1;
08163 }
08164 if (ier) {
08165 cgi_error("GridLocation %d not valid for %s", GridLocation, posit->label);
08166 return CG_ERROR;
08167 }
08168
08169 (*location) = GridLocation;
08170
08171
08172 if (cgi_posit_id(&posit_id)) return CG_ERROR;
08173 dim_vals = strlen(GridLocationName[GridLocation]);
08174 if (cgi_new_node(posit_id, "GridLocation", "GridLocation_t", &dummy_id,
08175 "C1", 1, &dim_vals, (void *)GridLocationName[GridLocation])) return CG_ERROR;
08176 return CG_OK;
08177 }
08178
08179 int cg_ordinal_write(int Ordinal) {
08180 int *ordinal;
08181 int ier=0;
08182 double posit_id;
08183
08184
08185 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
08186
08187 ordinal = cgi_ordinal_address(CG_MODE_WRITE, &ier);
08188 if (ordinal==0) return ier;
08189
08190 (*ordinal) = Ordinal;
08191
08192
08193 if (cgi_posit_id(&posit_id)) return CG_ERROR;
08194 if (cgi_write_ordinal(posit_id, Ordinal)) return CG_ERROR;
08195 return CG_OK;
08196 }
08197
08198 int cg_link_write(char const * nodename, char const * filename, char const * name_in_file) {
08199 double posit_id, link_id;
08200
08201
08202 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
08203 if (cgi_posit_id(&posit_id)) return CG_ERROR;
08204
08205
08206
08207 if (strcmp(posit->label,"DataArray_t") &&
08208 strcmp(posit->label,"UserDefinedData_t") &&
08209 strcmp(posit->label,"IntegralData_t") &&
08210 strcmp(posit->label,"DiscreteData_t") &&
08211 strcmp(posit->label,"ConvergenceHistory_t") &&
08212 strcmp(posit->label,"ReferenceState_t") &&
08213 strcmp(posit->label,"GasModel_t") &&
08214 strcmp(posit->label,"ViscosityModel_t") &&
08215 strcmp(posit->label,"ThermalConductivityModel_t") &&
08216 strcmp(posit->label,"TurbulenceModel_t") &&
08217 strcmp(posit->label,"TurbulenceClosure_t") &&
08218 strcmp(posit->label,"ThermalRelaxationModel_t") &&
08219 strcmp(posit->label,"ChemicalKineticsModel_t") &&
08220 strcmp(posit->label,"EMElectricFieldModel_t") &&
08221 strcmp(posit->label,"EMMagneticFieldModel_t") &&
08222 strcmp(posit->label,"EMConductivityModel_t") &&
08223 strcmp(posit->label,"GoverningEquations_t") &&
08224 strcmp(posit->label,"BCData_t") &&
08225 strcmp(posit->label,"BCDataSet_t") &&
08226 strcmp(posit->label,"Elements_t") &&
08227 strcmp(posit->label,"BC_t") &&
08228 strcmp(posit->label,"ZoneBC_t") &&
08229 strcmp(posit->label,"OversetHoles_t") &&
08230 strcmp(posit->label,"GridConnectivity_t") &&
08231 strcmp(posit->label,"GridConnectivity1to1_t") &&
08232 strcmp(posit->label,"ZoneGridConnectivity_t") &&
08233 strcmp(posit->label,"FlowSolution_t") &&
08234 strcmp(posit->label,"GridCoordinates_t") &&
08235 strcmp(posit->label,"RigidGridMotion_t") &&
08236 strcmp(posit->label,"ArbitraryGridMotion_t") &&
08237 strcmp(posit->label,"ZoneIterativeData_t") &&
08238 strcmp(posit->label,"BaseIterativeData_t") &&
08239 strcmp(posit->label,"Zone_t") &&
08240 strcmp(posit->label,"GeometryReference_t ") &&
08241 strcmp(posit->label,"Family_t") &&
08242 strcmp(posit->label,"CGNSBase_t") &&
08243 strcmp(posit->label,"Gravity_t") &&
08244 strcmp(posit->label,"Axisymmetry_t") &&
08245 strcmp(posit->label,"RotatingCoordinates_t") &&
08246 strcmp(posit->label,"BCProperty_t") &&
08247 strcmp(posit->label,"WallFunction_t") &&
08248 strcmp(posit->label,"Area_t") &&
08249 strcmp(posit->label,"GridConnectivityProperty_t") &&
08250 strcmp(posit->label,"Periodic_t") &&
08251 strcmp(posit->label,"AverageInterface_t")) {
08252 cgi_error("Links not supported under '%s' type node",posit->label);
08253 return CG_INCORRECT_PATH;
08254 }
08255
08256 #if DEBUG_LINKS
08257 printf("Modify link %s -> \"%s>%s\"\n",
08258 nodename, filename, name_in_file);
08259 #endif
08260
08261
08262
08263
08264
08265
08266
08267 if (cgio_create_link(cg->cgio, posit_id, nodename, filename,
08268 name_in_file, &link_id)) {
08269 cg_io_error("cgio_create_link");
08270 return CG_ERROR;
08271 }
08272 (cg->added)++;
08273 return CG_OK;
08274 }
08275
08276
08277 int cg_user_data_write(char const * UserDataName) {
08278 cgns_user_data *user_data;
08279 int ier=0;
08280 double posit_id;
08281
08282
08283 if (cgi_check_strlen(UserDataName)) return CG_ERROR;
08284 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
08285
08286 user_data = cgi_user_data_address(CG_MODE_WRITE, 0, UserDataName, &ier);
08287 if (user_data==0) return ier;
08288
08289 strcpy(user_data->name, UserDataName);
08290
08291
08292 user_data->id=0;
08293 user_data->link=0;
08294 user_data->ndescr=0;
08295 user_data->narrays=0;
08296 user_data->data_class=DataClassNull;
08297 user_data->units=0;
08298 user_data->location = Vertex;
08299 user_data->family_name[0] = '\0';
08300 user_data->ordinal = 0;
08301 user_data->ptset = 0;
08302 user_data->nuser_data = 0;
08303 user_data->user_data = 0;
08304
08305
08306 if (cgi_posit_id(&posit_id)) return CG_ERROR;
08307 if (cgi_new_node(posit_id, user_data->name, "UserDefinedData_t",
08308 &user_data->id, "MT", 0, 0, 0)) return CG_ERROR;
08309
08310 return CG_OK;
08311 }
08312
08313 int cg_rotating_write(float const *rot_rate, float const *rot_center) {
08314 cgns_rotating *rotating;
08315 cgns_base *base;
08316 int ier=0, n;
08317 double posit_id;
08318
08319
08320 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
08321
08322 rotating=cgi_rotating_address(CG_MODE_WRITE, &ier);
08323 if (rotating==0) return ier;
08324
08325 if (posit_base) {
08326 base = &cg->base[posit_base-1];
08327 } else {
08328 cgi_error("Can't find the base");
08329 return CG_ERROR;
08330 }
08331
08332 rotating->array = CGNS_NEW(cgns_array, 2);
08333 rotating->narrays=2;
08334
08335
08336 for (n=0; n<rotating->narrays; n++) {
08337 strcpy(rotating->array[n].data_type, "R4");
08338 rotating->array[n].data = (void *)malloc(base->phys_dim*sizeof(float));
08339 if (!rotating->array[n].data) {
08340 cgi_error("Error allocating rotating->array[n].data");
08341 return CG_ERROR;
08342 }
08343 rotating->array[n].data_dim=1;
08344 rotating->array[n].dim_vals[0]=base->phys_dim;
08345 }
08346 memcpy(rotating->array[0].data, rot_center, base->phys_dim*sizeof(float));
08347 memcpy(rotating->array[1].data, rot_rate, base->phys_dim*sizeof(float));
08348 strcpy(rotating->array[0].name, "RotationCenter");
08349 strcpy(rotating->array[1].name, "RotationRateVector");
08350
08351
08352 for (n=0; n<rotating->narrays; n++) {
08353 rotating->array[n].id=0;
08354 rotating->array[n].link=0;
08355 rotating->array[n].ndescr=0;
08356 rotating->array[n].data_class=DataClassNull;
08357 rotating->array[n].units=0;
08358 rotating->array[n].exponents=0;
08359 rotating->array[n].convert=0;
08360 }
08361
08362
08363 strcpy(rotating->name, "RotatingCoordinates");
08364 rotating->id=0;
08365 rotating->link=0;
08366 rotating->ndescr=0;
08367 rotating->data_class=DataClassNull;
08368 rotating->units=0;
08369 rotating->nuser_data=0;
08370
08371
08372 if (cgi_posit_id(&posit_id)) return CG_ERROR;
08373 if (cgi_write_rotating(posit_id, rotating)) return CG_ERROR;
08374
08375 return CG_OK;
08376 }
08377
08378 int cg_ptset_write(PointSetType_t ptset_type, int npnts, int const * pnts)
08379 {
08380 cgns_ptset *ptset = 0;
08381 int i, index_dim;
08382 int ier=0;
08383
08384
08385 if(npnts == 0 || pnts == NULL)
08386 {
08387 cgi_error("Invalid input: npoint=%d, point set type=%s",
08388 npnts, PointSetTypeName[ptset_type]);
08389 return CG_ERROR;
08390 }
08391
08392 if (ptset_type == PointList)
08393 {
08394 if (npnts <= 0)
08395 {
08396 cgi_error("Invalid input: npoint=%d, point set type=%s",
08397 npnts, PointSetTypeName[ptset_type]);
08398 return CG_ERROR;
08399 }
08400 } else if (ptset_type == PointRange)
08401 {
08402 if (npnts != 2)
08403 {
08404 cgi_error("Invalid input: npoint=%d, point set type=%s",
08405 npnts, PointSetTypeName[ptset_type]);
08406 return CG_ERROR;
08407 }
08408 } else
08409 {
08410 cgi_error("Invalid point set type: %d...?",ptset_type);
08411 return CG_ERROR;
08412 }
08413
08414 if (posit_base && posit_zone)
08415 index_dim = cg->base[posit_base-1].zone[posit_zone-1].index_dim;
08416 else {
08417 cgi_error("Can not properly resolve IndexDimension unless under a Zone_t node.");
08418 return CG_NO_INDEX_DIM;
08419 }
08420
08421
08422 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE))
08423 return CG_ERROR;
08424
08425 ptset = cgi_ptset_address(CG_MODE_WRITE, &ier);
08426 if (ptset==0)
08427 return ier;
08428
08429
08430 ptset->type = ptset_type;
08431 ptset->npts = npnts;
08432
08433 if (ptset_type == PointList)
08434 {
08435 ptset->size_of_patch = npnts;
08436 }
08437 else
08438 {
08439 ptset->size_of_patch = 1;
08440 for (i=0; i < index_dim; i++)
08441 ptset->size_of_patch = ptset->size_of_patch *
08442 (pnts[i+index_dim] - pnts[i]+1);
08443 }
08444
08445
08446 ptset->id = 0;
08447 ptset->link = 0;
08448 strcpy(ptset->name, PointSetTypeName[ptset->type]);
08449 strcpy(ptset->data_type,"I4");
08450
08451
08452 if (ptset->npts > 0)
08453 {
08454 double posit_id;
08455
08456
08457 if (cgi_posit_id(&posit_id))
08458 return CG_ERROR;
08459
08460 if (cgi_write_ptset(posit_id, ptset->name, ptset, index_dim,
08461 (void *)pnts))
08462 return CG_ERROR;
08463 }
08464
08465 return CG_OK;
08466 }
08467
08468 int cg_field_partial_write(int file_number, int B, int Z, int S,
08469 DataType_t type, char const *fieldname, int *rmin,
08470 int *rmax, void const *field_ptr, int *F) {
08471 cgns_zone *zone;
08472 cgns_sol *sol;
08473 cgns_array *field;
08474 int n, index, index_dim, dims[CGIO_MAX_DIMENSIONS];
08475
08476
08477 if (cgi_check_strlen(fieldname)) return CG_ERROR;
08478 if (type!=RealSingle && type!=RealDouble && type!=Integer) {
08479 cgi_error("Invalid datatype for solution array %s: %d",fieldname, type);
08480 return CG_ERROR;
08481 }
08482
08483 if(rmin == NULL || rmax == NULL) {
08484 cgi_error("NULL range value.");
08485 return CG_ERROR;
08486 }
08487
08488
08489 cg = cgi_get_file(file_number);
08490 if (cg == 0) return CG_ERROR;
08491
08492 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
08493
08494 zone = cgi_get_zone(cg, B, Z);
08495 if (zone==0) return CG_ERROR;
08496
08497 sol = cgi_get_sol(cg, B, Z, S);
08498 if (sol==0) return CG_ERROR;
08499
08500
08501 index_dim = zone->index_dim;
08502 if (cgi_datasize(index_dim, zone->nijk, sol->location,
08503 sol->rind_planes, dims)) return CG_ERROR;
08504 for (n = 0; n < index_dim; n++) {
08505 if (rmin[n] > rmax[n] || rmin[n] < 1 || rmax[n] > dims[n]) {
08506 cgi_error("Invalid index ranges.");
08507 return CG_ERROR;
08508 }
08509 }
08510
08511
08512 for (index=0; index<sol->nfields; index++) {
08513 if (strcmp(fieldname, sol->field[index].name)==0) {
08514 int m_start[CGIO_MAX_DIMENSIONS], m_end[CGIO_MAX_DIMENSIONS];
08515 int m_dim[CGIO_MAX_DIMENSIONS], stride[CGIO_MAX_DIMENSIONS];
08516
08517 field = &(sol->field[index]);
08518
08519 if (strcmp(field->data_type, cgi_adf_datatype(type))) {
08520 cgi_error("Mismatch in data types.");
08521 return CG_ERROR;
08522 }
08523 for (n = 0; n < field->data_dim; n++) {
08524 m_start[n] = 1;
08525 m_end[n] = rmax[n] - rmin[n] + 1;
08526 m_dim[n] = m_end[n];
08527 stride[n] = 1;
08528 }
08529
08530 if (cgio_write_data(cg->cgio, field->id, rmin, rmax, stride,
08531 field->data_dim, m_dim, m_start, m_end,
08532 stride, (void *)field_ptr)) {
08533 cg_io_error("cgio_write_data");
08534 return CG_ERROR;
08535 }
08536 return CG_OK;
08537 }
08538 }
08539
08540
08541 if (sol->nfields == 0) {
08542 sol->field = CGNS_NEW(cgns_array, sol->nfields+1);
08543 } else {
08544 sol->field = CGNS_RENEW(cgns_array, sol->nfields+1, sol->field);
08545 }
08546 field = &(sol->field[sol->nfields]);
08547 sol->nfields++;
08548 (*F) = sol->nfields;
08549
08550
08551 strcpy(field->data_type, cgi_adf_datatype(type));
08552 strcpy(field->name, fieldname);
08553 field->data_dim = index_dim;
08554 for (n = 0; n < index_dim; n++)
08555 field->dim_vals[n] = dims[n];
08556
08557
08558 field->id = 0;
08559 field->link= 0;
08560 field->data=0;
08561 field->ndescr= 0;
08562 field->data_class= DataClassNull;
08563 field->units= 0;
08564 field->exponents= 0;
08565 field->convert= 0;
08566
08567
08568 if (cgi_new_node_partial(sol->id, field->name, "DataArray_t", &field->id,
08569 field->data_type, index_dim, field->dim_vals, rmin, rmax,
08570 field_ptr))
08571 return CG_ERROR;
08572
08573 return CG_OK;
08574 }
08575
08576 int cg_coord_partial_write(int file_number, int B, int Z, DataType_t type,
08577 char const *coordname, int *rmin, int *rmax,
08578 void const *coord_ptr, int *C) {
08579 cgns_zone *zone;
08580 cgns_zcoor *zcoor;
08581 cgns_array *coord;
08582 int n, index, index_dim, dims[CGIO_MAX_DIMENSIONS];
08583
08584
08585 if (cgi_check_strlen(coordname)) return CG_ERROR;
08586 if (type!=RealSingle && type!=RealDouble) {
08587 cgi_error("Invalid datatype for coord. array: %d", type);
08588 return CG_ERROR;
08589 }
08590
08591 if(rmin == NULL || rmax == NULL) {
08592 cgi_error("NULL range value.");
08593 return CG_ERROR;
08594 }
08595
08596
08597 cg = cgi_get_file(file_number);
08598 if (cg == 0) return CG_ERROR;
08599
08600 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
08601
08602
08603 zone = cgi_get_zone(cg, B, Z);
08604 if (zone==0) return CG_ERROR;
08605
08606
08607 zcoor = cgi_get_zcoorGC(cg, B, Z);
08608 if (zcoor==0) return CG_ERROR;
08609
08610
08611 index_dim = zone->index_dim;
08612 for (n = 0; n < index_dim; n++) {
08613 dims[n] = zone->nijk[n] + zcoor->rind_planes[2*n] +
08614 zcoor->rind_planes[2*n+1];
08615 if (rmin[n] > rmax[n] || rmin[n] < 1 || rmax[n] > dims[n]) {
08616 cgi_error("Invalid index ranges.");
08617 return CG_ERROR;
08618 }
08619 }
08620
08621
08622 for (index=0; index<zcoor->ncoords; index++) {
08623 if (strcmp(coordname, zcoor->coord[index].name)==0) {
08624 int m_start[CGIO_MAX_DIMENSIONS], m_end[CGIO_MAX_DIMENSIONS];
08625 int m_dim[CGIO_MAX_DIMENSIONS], stride[CGIO_MAX_DIMENSIONS];
08626
08627 coord = &(zcoor->coord[index]);
08628
08629 if (strcmp(coord->data_type,cgi_adf_datatype(type))) {
08630 cgi_error("Mismatch in data types.");
08631 return CG_ERROR;
08632 }
08633 for (n = 0; n < coord->data_dim; n++) {
08634 m_start[n] = 1;
08635 m_end[n] = rmax[n] - rmin[n] + 1;
08636 m_dim[n] = m_end[n];
08637 stride[n] = 1;
08638 }
08639
08640 if (cgio_write_data(cg->cgio, coord->id, rmin, rmax, stride,
08641 coord->data_dim, m_dim, m_start, m_end,
08642 stride, (void *)coord_ptr)) {
08643 cg_io_error("cgio_write_data");
08644 return CG_ERROR;
08645 }
08646 return CG_OK;
08647 }
08648 }
08649
08650
08651 if (zcoor->ncoords == 0) {
08652 zcoor->coord = CGNS_NEW(cgns_array, zcoor->ncoords+1);
08653 } else {
08654 zcoor->coord = CGNS_RENEW(cgns_array, zcoor->ncoords+1, zcoor->coord);
08655 }
08656 coord = &(zcoor->coord[zcoor->ncoords]);
08657 zcoor->ncoords++;
08658 (*C) = zcoor->ncoords;
08659
08660
08661 strcpy(coord->data_type,cgi_adf_datatype(type));
08662 strcpy(coord->name,coordname);
08663 coord->id=0;
08664 coord->link=0;
08665 for (n = 0; n < index_dim; n++)
08666 coord->dim_vals[n] = dims[n];
08667 coord->data_dim=index_dim;
08668 coord->data=0;
08669 coord->ndescr=0;
08670 coord->data_class=DataClassNull;
08671 coord->units=0;
08672 coord->exponents=0;
08673 coord->convert=0;
08674
08675
08676 if (zcoor->id == 0) {
08677 if (cgi_new_node(zone->id, "GridCoordinates", "GridCoordinates_t",
08678 &zcoor->id, "MT", 0, 0, 0)) return CG_ERROR;
08679 }
08680
08681
08682 if (cgi_new_node_partial(zcoor->id, coord->name, "DataArray_t", &coord->id,
08683 coord->data_type, index_dim, coord->dim_vals, rmin, rmax,
08684 coord_ptr))
08685 return CG_ERROR;
08686
08687 return CG_OK;
08688 }
08689
08690 int cg_section_partial_write(int file_number, int B, int Z,
08691 char const * SectionName, ElementType_t type,
08692 int start, int end, int nbndry,
08693 int const * elements, int *S) {
08694 cgns_zone *zone;
08695 cgns_section *section;
08696 int index, ElementDataSize;
08697
08698
08699 if (cgi_check_strlen(SectionName)) return CG_ERROR;
08700
08701
08702
08703 if (type < 0) {
08704 cgi_error("Invalid element type defined for section '%s'",SectionName);
08705 return CG_ERROR;
08706 }
08707 if (start < 1 || (end-start) < 0) {
08708 cgi_error("Invalid element range defined for section '%s'",SectionName);
08709 return CG_ERROR;
08710 }
08711 if (nbndry > (end-start+1)) {
08712 cgi_error("Invalid boundary element number for section '%s'",SectionName);
08713 return CG_ERROR;
08714 }
08715 ElementDataSize = cgi_element_data_size(type, end-start+1, elements);
08716 if (ElementDataSize < 0) return CG_ERROR;
08717
08718
08719 cg = cgi_get_file(file_number);
08720 if (cg == 0) return CG_ERROR;
08721
08722 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
08723
08724 zone = cgi_get_zone(cg, B, Z);
08725 if (zone==0) return CG_ERROR;
08726
08727
08728 for (index=0; index<zone->nsections; index++) {
08729 if (strcmp(SectionName, zone->section[index].name)==0) {
08730 int i, n, size, num, offset;
08731 int oldsize, newsize, elemsize;
08732 int *oldelems, *newelems;
08733 double id;
08734
08735 section = &(zone->section[index]);
08736
08737
08738 if(type != section->el_type) {
08739 cgi_error("Mismatch in element types for section '%s'",SectionName);
08740 return CG_ERROR;
08741 }
08742
08743
08744 if (type == MIXED)
08745 elemsize = 2;
08746 else {
08747 if (cg_npe(type, &elemsize)) return CG_ERROR;
08748 if (elemsize <= 0) {
08749 cgi_error("Invalid element type");
08750 return CG_ERROR;
08751 }
08752 }
08753
08754 oldelems = (int *)section->connect->data;
08755 oldsize = section->connect->dim_vals[0];
08756 newsize = ElementDataSize;
08757
08758 if (end < section->range[0]) {
08759 newsize += oldsize;
08760 num = section->range[0] - end - 1;
08761 if (num > 0) newsize += (elemsize * num);
08762 } else if (start > section->range[1]) {
08763 newsize += oldsize;
08764 num = start - section->range[1] - 1;
08765 if (num > 0) newsize += (elemsize * num);
08766 } else {
08767
08768 if (start > section->range[0]) {
08769 size = cgi_element_data_size(type,
08770 start - section->range[0], oldelems);
08771 if (size < 0) return CG_ERROR;
08772 newsize += size;
08773 }
08774 if (end < section->range[1]) {
08775 num = end - section->range[0] + 1;
08776 offset = cgi_element_data_size(type, num, oldelems);
08777 if (offset < 0) return CG_ERROR;
08778 size = oldsize - offset;
08779 newsize += size;
08780 }
08781 }
08782
08783
08784
08785 newelems = (int *) malloc (newsize * sizeof(int));
08786 if (NULL == newelems) {
08787 cgi_error("Error allocating new connectivity data");
08788 return CG_ERROR;
08789 }
08790 n = 0;
08791 if (start <= section->range[0]) {
08792 memcpy(newelems, elements, ElementDataSize*sizeof(int));
08793 n += ElementDataSize;
08794 if (end < section->range[0]) {
08795 num = section->range[0] - end - 1;
08796 while (num-- > 0) {
08797 if (type == MIXED) {
08798 newelems[n++] = (int)NODE;
08799 newelems[n++] = 0;
08800 } else {
08801 for (i = 0; i < elemsize; i++)
08802 newelems[n++] = 0;
08803 }
08804 }
08805 memcpy(&newelems[n], oldelems, oldsize*sizeof(int));
08806 n += oldsize;
08807 } else if (end < section->range[1]) {
08808 num = end - section->range[0] + 1;
08809 offset = cgi_element_data_size(type, num, oldelems);
08810 if (offset < 0) return CG_ERROR;
08811 size = oldsize - offset;
08812 memcpy(&newelems[n], &oldelems[offset], size*sizeof(int));
08813 n += size;
08814 }
08815 } else if (start > section->range[1]) {
08816 memcpy(newelems, oldelems, oldsize*sizeof(int));
08817 n += oldsize;
08818 num = start - section->range[1] - 1;
08819 while (num-- > 0) {
08820 if (type == MIXED) {
08821 newelems[n++] = (int)NODE;
08822 newelems[n++] = 0;
08823 } else {
08824 for (i = 0; i < elemsize; i++)
08825 newelems[n++] = 0;
08826 }
08827 }
08828 memcpy(&newelems[n], elements, ElementDataSize*sizeof(int));
08829 n += ElementDataSize;
08830 } else {
08831 num = start - section->range[0];
08832 size = cgi_element_data_size(type, num, oldelems);
08833 memcpy(newelems, oldelems, size*sizeof(int));
08834 n += size;
08835 memcpy(&newelems[n], elements, ElementDataSize*sizeof(int));
08836 n += ElementDataSize;
08837 if (end < section->range[1]) {
08838 num = end - section->range[0] + 1;
08839 offset = cgi_element_data_size(type, num, oldelems);
08840 if (offset < 0) return CG_ERROR;
08841 size = oldsize - offset;
08842 memcpy(&newelems[n], &oldelems[offset], size*sizeof(int));
08843 n += size;
08844 }
08845 }
08846 if (n != newsize) {
08847 cgi_error("my counting is off !!!\n");
08848 return CG_ERROR;
08849 }
08850
08851 free(section->connect->data);
08852 section->connect->dim_vals[0] = newsize;
08853 section->connect->data = newelems;
08854
08855
08856
08857 offset = start < section->range[0] ?
08858 section->range[0] - start : 0;
08859 oldsize = section->range[1] - section->range[0] + 1;
08860
08861
08862
08863 if (start < section->range[0]) section->range[0] = start;
08864 if (end > section->range[1]) section->range[1] = end;
08865
08866
08867
08868 if (cgio_get_node_id(cg->cgio, section->id, "ElementRange", &id)) {
08869 cg_io_error("cgio_get_node_id");
08870 return CG_ERROR;
08871 }
08872 if (cgio_write_all_data(cg->cgio, id, section->range)) {
08873 cg_io_error("cgio_write_all_data");
08874 return CG_ERROR;
08875 }
08876
08877
08878
08879 if (cgio_set_dimensions(cg->cgio, section->connect->id,
08880 section->connect->data_type, 1,
08881 section->connect->dim_vals)) {
08882 cg_io_error("cgio_set_dimensions");
08883 return CG_ERROR;
08884 }
08885 if (cgio_write_all_data(cg->cgio, section->connect->id, newelems)) {
08886 cg_io_error("cgio_write_all_data");
08887 return CG_ERROR;
08888 }
08889
08890
08891
08892 if (section->parent) {
08893 int i, j;
08894 oldelems = (int *)section->parent->data;
08895 newsize = section->range[1] - section->range[0] + 1;
08896 newelems = (int *)malloc(4 * newsize * sizeof(int));
08897 if (NULL == newelems) {
08898 cgi_error("Error alocating new parent data");
08899 return CG_ERROR;
08900 }
08901 for (n = 0; n < 4*newsize; n++)
08902 newelems[n] = 0;
08903
08904 for (i = 0, num = 0; num < 4; num++) {
08905 j = num * newsize + offset;
08906 for (n = 0; n < oldsize; n++)
08907 newelems[j++] = oldelems[i++];
08908 }
08909
08910 offset = start - section->range[0];
08911 for (num = 0; num < 4; num++) {
08912 j = num * newsize + offset;
08913 for (n = start; n <= end; n++)
08914 newelems[j++] = 0;
08915 }
08916
08917 free(section->parent->data);
08918 section->parent->data = newelems;
08919 section->parent->dim_vals[0] = newsize;
08920
08921
08922
08923 if (cgio_set_dimensions(cg->cgio, section->parent->id,
08924 section->parent->data_type, 2,
08925 section->parent->dim_vals)) {
08926 cg_io_error("cgio_set_dimensions");
08927 return CG_ERROR;
08928 }
08929 if (cgio_write_all_data(cg->cgio, section->parent->id, newelems)) {
08930 cg_io_error("cgio_write_all_data");
08931 return CG_ERROR;
08932 }
08933 }
08934
08935 return CG_OK;
08936 }
08937 }
08938
08939 if (zone->nsections == 0) {
08940 zone->section = CGNS_NEW(cgns_section, zone->nsections+1);
08941 } else {
08942 zone->section = CGNS_RENEW(cgns_section, zone->nsections+1, zone->section);
08943 }
08944 section = &(zone->section[zone->nsections]);
08945 zone->nsections++;
08946 (*S) = zone->nsections;
08947
08948
08949 strcpy(section->name, SectionName);
08950 section->el_type = type;
08951 section->range[0] = start;
08952 section->range[1] = end;
08953 section->el_bound = nbndry;
08954
08955 section->connect = CGNS_NEW(cgns_array, 1);
08956 section->connect->data = (void *)malloc(ElementDataSize*sizeof(int));
08957 memcpy(section->connect->data, elements, ElementDataSize*sizeof(int));
08958 strcpy(section->connect->name,"ElementConnectivity");
08959 strcpy(section->connect->data_type,"I4");
08960 section->connect->data_dim=1;
08961 section->connect->dim_vals[0]=ElementDataSize;
08962
08963
08964 section->id=0;
08965 section->link=0;
08966 section->ndescr=0;
08967 section->parent = 0;
08968 section->nuser_data=0;
08969 section->rind_planes=0;
08970
08971
08972 section->connect->id=0;
08973 section->connect->link=0;
08974 section->connect->ndescr=0;
08975 section->connect->data_class=DataClassNull;
08976 section->connect->units=0;
08977 section->connect->exponents=0;
08978 section->connect->convert=0;
08979
08980
08981 if (cgi_write_section(zone->id, section)) return CG_ERROR;
08982 return CG_OK;
08983 }
08984
08985 int cg_parent_data_partial_write(int file_number, int B, int Z, int S,
08986 int start, int end,
08987 int const *parent_data) {
08988 cgns_section *section;
08989 cgns_array *parent;
08990 int *data, i, j, n;
08991 int num, size, offset;
08992
08993
08994 cg = cgi_get_file(file_number);
08995 if (cg == 0) return CG_ERROR;
08996
08997 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
08998
08999 section = cgi_get_section(cg, B, Z, S);
09000 if (section == 0) return CG_ERROR;
09001
09002
09003
09004 size = section->range[1] - section->range[0] + 1;
09005 if (start < section->range[0] || end > section->range[1] ||
09006 start > end) {
09007 cgi_error("Invalid element range for section '%s' parent data",
09008 section->name);
09009 return CG_ERROR;
09010 }
09011 offset = start - section->range[0];
09012 parent = section->parent;
09013
09014 if (parent) {
09015
09016
09017
09018 if (size != parent->dim_vals[0]) {
09019 cgi_error("internal errror - invalid parent data size !!!");
09020 return CG_ERROR;
09021 }
09022
09023 data = (int *)parent->data;
09024
09025 for (i = 0, num = 0; num < 4; num++) {
09026 j = num * size + offset;
09027 for (n = start; n <= end; n++)
09028 data[j++] = parent_data[i++];
09029 }
09030
09031 if (cgio_write_all_data(cg->cgio, parent->id, data)) {
09032 cg_io_error("cgio_write_all_data");
09033 return CG_ERROR;
09034 }
09035
09036 return CG_OK;
09037 }
09038
09039
09040
09041 data = (int *) malloc (4*size*sizeof(int));
09042 if (NULL == data) {
09043 cgi_error("Error allocating parent data");
09044 return CG_ERROR;
09045 }
09046 for (n = 0; n < 4*size; n++)
09047 data[n] = 0;
09048 for (i = 0, num = 0; num < 4; num++) {
09049 j = num * size + offset;
09050 for (n = start; n <= end; n++)
09051 data[j++] = parent_data[i++];
09052 }
09053
09054 section->parent = CGNS_NEW(cgns_array, 1);
09055 parent = section->parent;
09056 strcpy(parent->data_type, "I4");
09057 strcpy(parent->name, "ParentData");
09058 parent->data = (void *)data;
09059 parent->data_dim =2;
09060 parent->dim_vals[0]=size;
09061 parent->dim_vals[1]=4;
09062
09063
09064 parent->id=0;
09065 parent->link=0;
09066 parent->ndescr=0;
09067 parent->data_class=DataClassNull;
09068 parent->units=0;
09069 parent->exponents=0;
09070 parent->convert=0;
09071
09072 if(cgi_write_array(section->id, section->parent)) return CG_ERROR;
09073
09074 return CG_OK;
09075 }
09076
09077 int cg_elements_partial_read(int file_number, int B, int Z, int S,
09078 int start, int end, int *elements, int *parent_data) {
09079 cgns_section *section;
09080 int offset, size;
09081 int *data;
09082
09083 cg = cgi_get_file(file_number);
09084 if (cg == 0) return CG_ERROR;
09085
09086
09087 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
09088
09089 section = cgi_get_section(cg, B, Z, S);
09090 if (section == 0) return CG_ERROR;
09091
09092
09093
09094
09095 if(start > end || start < section->range[0] ||
09096 end > section->range[1]) {
09097 cgi_error("Error in requested element data range.");
09098 return CG_ERROR;
09099 }
09100 data = (int *)section->connect->data;
09101
09102 offset = cgi_element_data_size(section->el_type,
09103 start - section->range[0], data);
09104 size = cgi_element_data_size(section->el_type,
09105 end - start + 1, &data[offset]);
09106
09107 memcpy(elements, &data[offset], size*sizeof(int));
09108
09109 if (section->parent && parent_data) {
09110 int i, j, n, nn;
09111 data = (int *)section->parent->data;
09112
09113 offset = start - section->range[0];
09114 size = section->range[1] - section->range[0] + 1;
09115
09116 for (n = 0, j = 0; j < 4; j++) {
09117 nn = j * size + offset;
09118 for (i = start; i <= end; i++)
09119 parent_data[n++] = data[nn++];
09120 }
09121 }
09122 return CG_OK;
09123 }
09124
09125 int cg_ElementPartialSize(int file_number, int B, int Z, int S,
09126 int start, int end, int *ElementDataSize) {
09127 cgns_section *section;
09128 int size, offset, *data;
09129
09130 cg = cgi_get_file(file_number);
09131 if (cg == 0) return CG_ERROR;
09132
09133
09134 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
09135
09136 section = cgi_get_section(cg, B, Z, S);
09137 if (section == 0) return CG_ERROR;
09138
09139 if (start > end || start < section->range[0] ||
09140 end > section->range[1]) {
09141 cgi_error("Invalid range for section '%s'", section->name);
09142 return CG_ERROR;
09143 }
09144
09145 data = (int *)section->connect->data;
09146 offset = cgi_element_data_size(section->el_type,
09147 start - section->range[0], data);
09148 if (offset < 0) return CG_ERROR;
09149 size = cgi_element_data_size(section->el_type,
09150 end - start + 1, &data[offset]);
09151 if (size < 0) return CG_ERROR;
09152 *ElementDataSize = size;
09153 return CG_OK;
09154 }
09155
09156 int cg_bcdataset_write(char *name, BCType_t BCType, BCDataType_t BCDataType)
09157 {
09158 cgns_dataset *dataset = 0;
09159 cgns_bcdata *bcdata = 0;
09160 int length;
09161 int ierr=0;
09162 double posit_id;
09163
09164
09165 if (BCType<0 || BCType>=NofValidBCTypes) {
09166 cgi_error("Invalid BCType: %d",BCType);
09167 return CG_ERROR;
09168 }
09169
09170 if (BCDataType<0 || BCDataType>=NofValidBCDataTypes) {
09171 cgi_error("BCDataType %d not valid",BCDataType);
09172 return CG_ERROR;
09173 }
09174
09175 if (cgi_check_strlen(name)) return CG_ERROR;
09176
09177 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_WRITE)) return CG_ERROR;
09178
09179 if (strcmp(posit->label,"FamilyBC_t")==0)
09180 {
09181 cgns_fambc *fambc = (cgns_fambc *)posit->posit;
09182 cgns_dataset *dataset_tmp = fambc->dataset;
09183 int index, ndataset = fambc->ndataset;
09184
09185 for (index=0; index < ndataset; ++index)
09186 if (strcmp(name, dataset_tmp[index].name)==0)
09187 dataset = &dataset_tmp[index];
09188 }
09189
09190 if(dataset)
09191 {
09192
09193 if (dataset->dirichlet && BCDataType==Dirichlet)
09194 {
09195 if (cg->mode == CG_MODE_WRITE) {
09196 cgi_error("Dirichlet data already defined under BCDataSet_t '%s'",
09197 dataset->name);
09198 return CG_ERROR;
09199 } else {
09200 if (cgi_delete_node(dataset->id, dataset->dirichlet->id))
09201 return CG_ERROR;
09202 cgi_free_bcdata(dataset->dirichlet);
09203 }
09204 }
09205 else if(dataset->neumann && BCDataType==Neumann)
09206 {
09207 if (cg->mode == CG_MODE_WRITE) {
09208 cgi_error("Neumann data already defined under BCDataSet_t '%s'",
09209 dataset->name);
09210 return CG_ERROR;
09211 } else {
09212 if (cgi_delete_node(dataset->id, dataset->neumann->id))
09213 return CG_ERROR;
09214 cgi_free_bcdata(dataset->neumann);
09215 }
09216 }
09217 }
09218 else
09219 {
09220
09221 dataset = cgi_bcdataset_address(CG_MODE_WRITE, 0, name, &ierr);
09222 if (dataset == 0) return ierr;
09223
09224
09225 dataset->type = BCType;
09226 strcpy(dataset->name, name);
09227
09228
09229 dataset->id = 0;
09230 dataset->link=0;
09231 dataset->ndescr=0;
09232 dataset->dirichlet=0;
09233 dataset->neumann=0;
09234 dataset->state=0;
09235 dataset->data_class=DataClassNull;
09236 dataset->units=0;
09237 dataset->nuser_data=0;
09238
09239
09240 if (cgi_posit_id(&posit_id))
09241 return CG_ERROR;
09242
09243
09244 length = strlen(BCTypeName[dataset->type]);
09245 if (cgi_new_node(posit_id, dataset->name, "BCDataSet_t", &dataset->id,
09246 "C1", 1, &length, (void *)BCTypeName[dataset->type]))
09247 return CG_ERROR;
09248 }
09249
09250 if (BCDataType==Dirichlet) {
09251 if ( !dataset->dirichlet)
09252 dataset->dirichlet = CGNS_NEW(cgns_bcdata,1);
09253
09254 strcpy(dataset->dirichlet->name, "DirichletData");
09255 bcdata = dataset->dirichlet;
09256 } else if(BCDataType==Neumann){
09257 if ( !dataset->neumann)
09258 dataset->neumann = CGNS_NEW(cgns_bcdata,1);
09259
09260 strcpy(dataset->neumann->name, "NeumannData");
09261 bcdata = dataset->neumann;
09262 }
09263 else {
09264 cgi_error("BCDataType is not Dirichlet or Neumann");
09265 return CG_ERROR;
09266 }
09267
09268
09269 bcdata->id = 0;
09270 bcdata->link=0;
09271 bcdata->ndescr=0;
09272 bcdata->data_class=DataClassNull;
09273 bcdata->units=0;
09274 bcdata->narrays=0;
09275 bcdata->nuser_data=0;
09276
09277 if (cgi_new_node(dataset->id, bcdata->name, "BCData_t", &bcdata->id,
09278 "MT", 0, 0, 0)) return CG_ERROR;
09279
09280 return CG_OK;
09281 }
09282
09283 int cg_bcdataset_info(int *n_dataset)
09284 {
09285
09286 if (posit == 0) {
09287 cgi_error("No current position set by cg_goto\n");
09288 (*n_dataset) = 0;
09289 return CG_ERROR;
09290 }
09291
09292
09293
09294
09295
09296
09297
09298 if(strcmp(posit->label,"FamilyBC_t") ==0)
09299 {
09300 cgns_fambc *fambc = (cgns_fambc *)posit->posit;
09301 *n_dataset = fambc->ndataset;
09302 }
09303 else{
09304 cgi_error("FamilyBC_t node not supported under '%s' type node",posit->label);
09305
09306 return CG_INCORRECT_PATH;
09307 }
09308
09309 return CG_OK;
09310 }
09311
09312 int cg_bcdataset_read(int index, char *name, BCType_t *BCType,
09313 int *DirichletFlag, int *NeumannFlag)
09314 {
09315 cgns_dataset *dataset;
09316 int ier = 0;
09317
09318 if (cgi_check_mode(cg->filename, cg->mode, CG_MODE_READ)) return CG_ERROR;
09319
09320 dataset = cgi_bcdataset_address(CG_MODE_READ, index, NULL, &ier);
09321 if (dataset==0) return CG_ERROR;
09322
09323 strcpy(name, dataset->name);
09324 *BCType = dataset->type;
09325 if (dataset->dirichlet) *DirichletFlag=1;
09326 else *DirichletFlag=0;
09327 if (dataset->neumann) *NeumannFlag=1;
09328 else *NeumannFlag=0;
09329
09330 return CG_OK;
09331 }
09332
09333
09334 int cg_npe(ElementType_t type, int *npe) {
09335 static int el_size[NofValidElementTypes] = {
09336 0,
09337 0,
09338 1,
09339 2,
09340 3,
09341 3,
09342 6,
09343 4,
09344 8,
09345 9,
09346 4,
09347 10,
09348 5,
09349 13,
09350 14,
09351 6,
09352 15,
09353 18,
09354 8,
09355 20,
09356 27,
09357 0,
09358 0,
09359 0, };
09360 if(type < 0 || type >= NofValidElementTypes) {
09361 *npe = -1;
09362 cgi_error("Invalid element type");
09363 return CG_ERROR;
09364
09365 }
09366 (*npe) = el_size[type];
09367 return CG_OK;
09368 }
09369
09370
09371
09372
09373
09374 int cg_delete_node(char *node_name) {
09375 int n, m, index_dim;
09376 double posit_id, node_id;
09377 char_33 node_label;
09378
09379
09380 if (cg->mode != CG_MODE_MODIFY) {
09381 cgi_error("File %s must be opened in mode modify to delete a node", cg->filename);
09382 return CG_ERROR;
09383 }
09384
09385 if (cgi_posit_id(&posit_id)) return CG_ERROR;
09386
09387
09388 if (cgio_get_node_id(cg->cgio, posit_id, node_name, &node_id)) {
09389 cg_io_error("cgio_get_node_id");
09390 return CG_ERROR;
09391 }
09392
09393 if (cgio_get_label(cg->cgio, node_id, node_label)) {
09394 cg_io_error("cgio_get_label");
09395 return CG_ERROR;
09396 }
09397
09398
09399 if (
09400 (strcmp(posit->label,"Zone_t")==0 &&
09401 strcmp(node_label,"ZoneType_t")==0 ) ||
09402
09403 (strcmp(posit->label,"GridConnectivity1to1_t")==0 &&
09404 (strcmp(node_name,"PointRange")==0 ||
09405 strcmp(node_name,"PointRangeDonor")==0) ) ||
09406
09407 (strcmp(posit->label,"OversetHoles_t")==0 &&
09408 (strcmp(node_label,"IndexRange_t")==0 ||
09409 strcmp(node_name,"PointList")==0) ) ||
09410
09411 (strcmp(posit->label,"GridConnectivity_t")==0 &&
09412 (strcmp(node_name,"PointRange")==0 ||
09413 strcmp(node_name,"PointList")==0 ||
09414 strcmp(node_name,"CellListDonor")==0 ||
09415 strcmp(node_name,"PointListDonor")==0 ||
09416 strcmp(node_name,"InterpolantsDonor")==0) ) ||
09417
09418 (strcmp(posit->label,"BC_t")==0 &&
09419 (strcmp(node_name,"PointList")==0 ||
09420 strcmp(node_name,"PointRange")==0 ||
09421 strcmp(node_name,"ElementList")==0 ||
09422 strcmp(node_name,"ElementRange")==0) ) ||
09423
09424 (strcmp(posit->label,"GeometryReference_t")==0 &&
09425 (strcmp(node_name,"GeometryFile")==0 ||
09426 strcmp(node_name,"GeometryFormat")==0) ) ||
09427
09428 (strcmp(posit->label,"Elements_t")==0 &&
09429 (strcmp(node_name,"ElementRange")==0 ||
09430 strcmp(node_name,"ElementConnectivity")==0) ) ||
09431
09432 (strcmp(posit->label,"Gravity_t")==0 &&
09433 strcmp(node_name,"GravityVector")==0) ||
09434
09435 (strcmp(posit->label,"Axisymmetry_t")==0 &&
09436 (strcmp(node_name,"AxisymmetryReferencePoint")==0 ||
09437 strcmp(node_name,"AxisymmetryAxisVector")==0) ) ||
09438
09439 (strcmp(posit->label,"RotatingCoordinates_t")==0 &&
09440 (strcmp(node_name,"RotationCenter")==0 ||
09441 strcmp(node_name,"RotationRateVector")==0) ) ||
09442
09443 (strcmp(posit->label,"WallFunction_t")==0 &&
09444 strcmp(node_label,"WallFunctionType_t")==0) ||
09445
09446 (strcmp(posit->label,"Area_t")==0 &&
09447 (strcmp(node_label,"AreaType_t")==0 ||
09448 strcmp(node_label,"DataArray_t")==0) ) ||
09449
09450 (strcmp(posit->label,"Periodic_t")==0 &&
09451 strcmp(node_label,"DataArray_t")==0) ||
09452
09453 (strcmp(posit->label,"AverageInterface_t")==0 &&
09454 strcmp(node_label,"AverageInterfaceType_t")==0)
09455
09456 ) {
09457 cgi_error("Node '%s' under '%s' can not be deleted",node_name,posit->label);
09458 return CG_ERROR;
09459 }
09460
09461
09462 if (cgi_delete_node(posit_id, node_id)) {
09463
09464 return CG_ERROR;
09465 }
09466
09467
09468
09469 if (strcmp(posit->label,"CGNSBase_t")==0) {
09470 cgns_base *parent = (cgns_base *)posit->posit;
09471
09472
09473 if (strcmp(node_label,"Zone_t")==0) CGNS_DELETE_SHIFT(nzones, zone)
09474 else if (strcmp(node_label,"Family_t")==0) CGNS_DELETE_SHIFT(nfamilies, family)
09475 else if (strcmp(node_label,"IntegralData_t")==0) CGNS_DELETE_SHIFT(nintegrals, integral)
09476 else if (strcmp(node_label,"Descriptor_t")==0) CGNS_DELETE_SHIFT(ndescr, descr)
09477 else if (strcmp(node_label,"UserDefinedData_t")==0) CGNS_DELETE_SHIFT(nuser_data, user_data)
09478
09479
09480 else if (strcmp(node_name,"SimulationType")==0) {
09481 parent->type = SimulationTypeNull;
09482 parent->type_id = 0;
09483 }
09484 else if (strcmp(node_label,"BaseIterativeData_t")==0) parent->biter=0;
09485 else if (strcmp(node_name,"GlobalConvergenceHistory")==0) parent->converg=0;
09486 else if (strcmp(node_name,"FlowEquationSet")==0) parent->equations=0;
09487 else if (strcmp(node_name,"DimensionalUnits")==0) parent->units=0;
09488 else if (strcmp(node_name,"ReferenceState")==0) parent->state=0;
09489 else if (strcmp(node_name,"DataClass")==0) parent->data_class = DataClassNull;
09490 else if (strcmp(node_name,"Gravity")==0) parent->gravity=0;
09491 else if (strcmp(node_name,"Axisymmetry")==0) parent->axisym=0;
09492 else if (strcmp(node_name,"RotatingCoordinates")==0) parent->rotating=0;
09493
09494
09495 } else if (strcmp(posit->label,"Zone_t")==0) {
09496 cgns_zone *parent = (cgns_zone *)posit->posit;
09497 if (strcmp(node_label,"GridCoordinates_t")==0) CGNS_DELETE_SHIFT(nzcoor, zcoor)
09498 else if (strcmp(node_label,"DiscreteData_t")==0) CGNS_DELETE_SHIFT(ndiscrete, discrete)
09499 else if (strcmp(node_label,"Elements_t")==0) CGNS_DELETE_SHIFT(nsections, section)
09500 else if (strcmp(node_label,"FlowSolution_t")==0) CGNS_DELETE_SHIFT(nsols, sol)
09501 else if (strcmp(node_label,"RigidGridMotion_t")==0)CGNS_DELETE_SHIFT(nrmotions, rmotion)
09502 else if (strcmp(node_label,"ArbitraryGridMotion_t")==0) CGNS_DELETE_SHIFT(namotions, amotion)
09503 else if (strcmp(node_label,"IntegralData_t")==0) CGNS_DELETE_SHIFT(nintegrals, integral)
09504 else if (strcmp(node_label,"UserDefinedData_t")==0) CGNS_DELETE_SHIFT(nuser_data, user_data)
09505 else if (strcmp(node_label,"Descriptor_t")==0) CGNS_DELETE_SHIFT(ndescr, descr)
09506 else if (strcmp(node_name,"ZoneBC")==0) parent->zboco=0;
09507 else if (strcmp(node_name,"Ordinal")==0) parent->ordinal=0;
09508 else if (strcmp(node_name,"ZoneGridConnectivity")==0) parent->zconn=0;
09509 else if (strcmp(node_label,"ZoneIterativeData_t")==0) parent->ziter=0;
09510 else if (strcmp(node_name,"ReferenceState")==0) parent->state=0;
09511 else if (strcmp(node_name,"DataClass")==0) parent->data_class = DataClassNull;
09512 else if (strcmp(node_name,"FamilyName")==0) parent->family_name[0]='\0';
09513 else if (strcmp(node_name,"DimensionalUnits")==0) parent->units=0;
09514 else if (strcmp(node_name,"FlowEquationSet")==0) parent->equations=0;
09515 else if (strcmp(node_name,"ZoneConvergenceHistory")==0) parent->converg=0;
09516 else if (strcmp(node_name,"RotatingCoordinates")==0) parent->rotating=0;
09517
09518
09519
09520 } else if (strcmp(posit->label,"GridCoordinates_t")==0) {
09521 cgns_zcoor *parent = (cgns_zcoor *)posit->posit;
09522 if (strcmp(node_label,"DataArray_t")==0) CGNS_DELETE_SHIFT(ncoords, coord)
09523 else if (strcmp(node_label,"Descriptor_t")==0) CGNS_DELETE_SHIFT(ndescr, descr)
09524 else if (strcmp(node_label,"UserDefinedData_t")==0) CGNS_DELETE_SHIFT(nuser_data, user_data)
09525 else if (strcmp(node_name,"Rind")==0) {
09526 if (posit_base && posit_zone) {
09527 index_dim = cg->base[posit_base-1].zone[posit_zone-1].index_dim;
09528 } else {
09529 cgi_error("Can't find IndexDimension in cg_delete");
09530 return CG_NO_INDEX_DIM;
09531 }
09532 for (n=0; n<2*index_dim; n++) parent->rind_planes[n] = 0;
09533 }
09534 else if (strcmp(node_name,"DataClass")==0) parent->data_class = DataClassNull;
09535 else if (strcmp(node_name,"DimensionalUnits")==0) parent->units=0;
09536
09537
09538 } else if (strcmp(posit->label,"DataArray_t")==0) {
09539 cgns_array *parent = (cgns_array *)posit->posit;
09540 if (strcmp(node_label,"Descriptor_t")==0) CGNS_DELETE_SHIFT(ndescr, descr)
09541 else if (strcmp(node_name,"DataClass")==0) parent->data_class = DataClassNull;
09542 else if (strcmp(node_name,"DimensionalExponents")==0) parent->exponents=0;
09543 else if (strcmp(node_name,"DataConversion")==0) parent->convert=0;
09544 else if (strcmp(node_name,"DimensionalUnits")==0) parent->units=0;
09545
09546
09547 } else if (strcmp(posit->label,"FlowSolution_t")==0) {
09548 cgns_sol *parent = (cgns_sol *)posit->posit;
09549 if (strcmp(node_label,"Descriptor_t")==0) CGNS_DELETE_SHIFT(ndescr, descr)
09550 else if (strcmp(node_label,"UserDefinedData_t")==0) CGNS_DELETE_SHIFT(nuser_data, user_data)
09551 else if (strcmp(node_label,"DataArray_t")==0) CGNS_DELETE_SHIFT(nfields, field)
09552 else if (strcmp(node_name,"DataClass")==0) parent->data_class = DataClassNull;
09553 else if (strcmp(node_name,"DimensionalUnits")==0) parent->units=0;
09554 else if (strcmp(node_name,"GridLocation")==0) parent->location=GridLocationNull;
09555 else if (strcmp(node_name,"Rind")==0) {
09556 if (posit_base && posit_zone) {
09557 index_dim = cg->base[posit_base-1].zone[posit_zone-1].index_dim;
09558 } else {
09559 cgi_error("Can't find IndexDimension in cg_delete");
09560 return CG_NO_INDEX_DIM;
09561 }
09562 for (n=0; n<2*index_dim; n++) parent->rind_planes[n] = 0;
09563 }
09564
09565
09566 } else if (strcmp(posit->label,"ZoneGridConnectivity_t")==0) {
09567 cgns_zconn *parent = (cgns_zconn *)posit->posit;
09568 if (strcmp(node_label,"Descriptor_t")==0) CGNS_DELETE_SHIFT(ndescr, descr)
09569 else if (strcmp(node_label,"UserDefinedData_t")==0) CGNS_DELETE_SHIFT(nuser_data, user_data)
09570 else if (strcmp(node_label,"GridConnectivity1to1_t")==0) CGNS_DELETE_SHIFT(n1to1, one21)
09571 else if (strcmp(node_label,"GridConnectivity_t")==0) CGNS_DELETE_SHIFT(nconns, conn)
09572 else if (strcmp(node_label,"OversetHoles_t")==0) CGNS_DELETE_SHIFT(nholes, hole)
09573
09574
09575 } else if (strcmp(posit->label,"OversetHoles_t")==0) {
09576 cgns_hole *parent = (cgns_hole *)posit->posit;
09577 if (strcmp(node_label,"Descriptor_t")==0) CGNS_DELETE_SHIFT(ndescr, descr)
09578 else if (strcmp(node_label,"UserDefinedData_t")==0) CGNS_DELETE_SHIFT(nuser_data, user_data)
09579 else if (strcmp(node_name,"GridLocation")==0) parent->location=GridLocationNull;
09580
09581
09582
09583 } else if (strcmp(posit->label,"GridConnectivity_t")==0) {
09584 cgns_conn *parent = (cgns_conn *)posit->posit;
09585 if (strcmp(node_label,"Descriptor_t")==0) CGNS_DELETE_SHIFT(ndescr, descr)
09586 else if (strcmp(node_label,"UserDefinedData_t")==0) CGNS_DELETE_SHIFT(nuser_data, user_data)
09587 else if (strcmp(node_name,"InterpolantsDonor")==0) {
09588 if (parent->dptset.type==CellListDonor) {
09589 cgi_error("Node '%s' under '%s' can not be deleted",node_name,posit->label);
09590 return CG_ERROR;
09591 } else {
09592 CGNS_DELETE_SHIFT(narrays, interpolants)
09593 }
09594 }
09595 else if (strcmp(node_name,"GridLocation")==0) parent->location=GridLocationNull;
09596 else if (strcmp(node_name,"Ordinal")==0) parent->ordinal=0;
09597 else if (strcmp(node_name,"GridConnectivityType")==0) parent->type=GridConnectivityTypeNull;
09598 else if (strcmp(node_name,"GridConnectivityProperty")==0) parent->cprop=0;
09599
09600
09601
09602 } else if (strcmp(posit->label,"GridConnectivity1to1_t")==0) {
09603 cgns_1to1 *parent = (cgns_1to1 *)posit->posit;
09604 if (strcmp(node_label,"Descriptor_t")==0) CGNS_DELETE_SHIFT(ndescr, descr)
09605 else if (strcmp(node_label,"UserDefinedData_t")==0) CGNS_DELETE_SHIFT(nuser_data, user_data)
09606 else if (strcmp(node_name,"Ordinal")==0) parent->ordinal=0;
09607
09608
09609
09610 } else if (strcmp(posit->label,"ZoneBC_t")==0) {
09611 cgns_zboco *parent = (cgns_zboco *)posit->posit;
09612 if (strcmp(node_label,"Descriptor_t")==0) CGNS_DELETE_SHIFT(ndescr, descr)
09613 else if (strcmp(node_label,"UserDefinedData_t")==0) CGNS_DELETE_SHIFT(nuser_data, user_data)
09614 else if (strcmp(node_label,"BC_t")==0) CGNS_DELETE_SHIFT(nbocos, boco)
09615 else if (strcmp(node_name,"DataClass")==0) parent->data_class = DataClassNull;
09616 else if (strcmp(node_name,"DimensionalUnits")==0) parent->units=0;
09617 else if (strcmp(node_name,"ReferenceState")==0) parent->state=0;
09618
09619
09620 } else if (strcmp(posit->label,"BC_t")==0) {
09621 cgns_boco *parent = (cgns_boco *)posit->posit;
09622 if (strcmp(node_label,"Descriptor_t")==0) CGNS_DELETE_SHIFT(ndescr, descr)
09623 else if (strcmp(node_label,"UserDefinedData_t")==0) CGNS_DELETE_SHIFT(nuser_data, user_data)
09624 else if (strcmp(node_label,"BCDataSet_t")==0) CGNS_DELETE_SHIFT(ndataset, dataset)
09625 else if (strcmp(node_name,"DataClass")==0) parent->data_class = DataClassNull;
09626 else if (strcmp(node_name,"DimensionalUnits")==0) parent->units=0;
09627 else if (strcmp(node_name,"GridLocation")==0) parent->location=GridLocationNull;
09628 else if (strcmp(node_name,"InwardNormalIndex")==0) parent->Nindex=0;
09629 else if (strcmp(node_name,"InwardNormalList")==0) parent->normal=0;
09630 else if (strcmp(node_name,"ReferenceState")==0) parent->state=0;
09631 else if (strcmp(node_name,"FamilyName")==0) parent->family_name[0]='\0';
09632 else if (strcmp(node_name,"Ordinal")==0) parent->ordinal=0;
09633 else if (strcmp(node_name,"BCProperty")==0) parent->bprop=0;
09634
09635
09636
09637 } else if (strcmp(posit->label,"BCDataSet_t")==0) {
09638 cgns_dataset *parent = (cgns_dataset *)posit->posit;
09639 if (strcmp(node_label,"Descriptor_t")==0) CGNS_DELETE_SHIFT(ndescr, descr)
09640 else if (strcmp(node_label,"UserDefinedData_t")==0) CGNS_DELETE_SHIFT(nuser_data, user_data)
09641 else if (strcmp(node_name,"DataClass")==0) parent->data_class = DataClassNull;
09642 else if (strcmp(node_name,"DimensionalUnits")==0) parent->units=0;
09643 else if (strcmp(node_name,"DirichletData")==0) parent->dirichlet=0;
09644 else if (strcmp(node_name,"NeumannData")==0) parent->neumann=0;
09645 else if (strcmp(node_name,"ReferenceState")==0) parent->state=0;
09646 else if (strcmp(node_name,"GridLocation")==0) parent->location=GridLocationNull;
09647
09648
09649
09650 } else if (strcmp(posit->label,"BCData_t")==0) {
09651 cgns_bcdata *parent = (cgns_bcdata *)posit->posit;
09652 if (strcmp(node_label,"Descriptor_t")==0) CGNS_DELETE_SHIFT(ndescr, descr)
09653 else if (strcmp(node_label,"UserDefinedData_t")==0) CGNS_DELETE_SHIFT(nuser_data, user_data)
09654 else if (strcmp(node_label,"DataArray_t")==0) CGNS_DELETE_SHIFT(narrays, array)
09655 else if (strcmp(node_name,"DataClass")==0) parent->data_class = DataClassNull;
09656 else if (strcmp(node_name,"DimensionalUnits")==0) parent->units=0;
09657
09658
09659 } else if (strcmp(posit->label,"DiscreteData_t")==0) {
09660 cgns_discrete *parent = (cgns_discrete *)posit->posit;
09661 if (strcmp(node_label,"Descriptor_t")==0) CGNS_DELETE_SHIFT(ndescr, descr)
09662 else if (strcmp(node_label,"UserDefinedData_t")==0) CGNS_DELETE_SHIFT(nuser_data, user_data)
09663 else if (strcmp(node_label,"DataArray_t")==0) CGNS_DELETE_SHIFT(narrays, array)
09664 else if (strcmp(node_name,"DataClass")==0) parent->data_class = DataClassNull;
09665 else if (strcmp(node_name,"DimensionalUnits")==0) parent->units=0;
09666 else if (strcmp(node_name,"GridLocation")==0) parent->location=GridLocationNull;
09667 else if (strcmp(node_name,"Rind")==0) {
09668 if (posit_base && posit_zone) {
09669 index_dim = cg->base[posit_base-1].zone[posit_zone-1].index_dim;
09670 } else {
09671 cgi_error("Can't find IndexDimension in cg_delete");
09672 return CG_NO_INDEX_DIM;
09673 }
09674 for (n=0; n<2*index_dim; n++) parent->rind_planes[n] = 0;
09675 }
09676
09677
09678 } else if (strcmp(posit->label,"FlowEquationSet_t")==0) {
09679 cgns_equations *parent = (cgns_equations *)posit->posit;
09680 if (strcmp(node_label,"Descriptor_t")==0) CGNS_DELETE_SHIFT(ndescr, descr)
09681 else if (strcmp(node_label,"UserDefinedData_t")==0) CGNS_DELETE_SHIFT(nuser_data, user_data)
09682 else if (strcmp(node_name,"DataClass")==0) parent->data_class = DataClassNull;
09683 else if (strcmp(node_name,"DimensionalUnits")==0) parent->units=0;
09684 else if (strcmp(node_name,"GoverningEquations")==0) parent->governing=0;
09685 else if (strcmp(node_name,"GasModel")==0) parent->gas=0;
09686 else if (strcmp(node_name,"ViscosityModel")==0) parent->visc=0;
09687 else if (strcmp(node_name,"ThermalRelaxationModel")==0) parent->relaxation=0;
09688 else if (strcmp(node_name,"ThermalConductivityModel")==0) parent->conduct=0;
09689 else if (strcmp(node_name,"ChemicalKineticsModel")==0) parent->chemkin=0;
09690 else if (strcmp(node_name,"EMElectricFieldModel")==0) parent->elecfield=0;
09691 else if (strcmp(node_name,"EMMagneticFieldModel")==0) parent->magnfield=0;
09692 else if (strcmp(node_name,"EMConductivityModel")==0) parent->emconduct=0;
09693 else if (strcmp(node_name,"TurbulenceModel")==0) parent->turbulence=0;
09694 else if (strcmp(node_name,"TurbulenceClosure")==0) parent->closure=0;
09695 else if (strcmp(node_name,"EquationDimension")==0) parent->equation_dim=0;
09696
09697
09698 } else if (strcmp(posit->label,"GoverningEquations_t")==0) {
09699 cgns_governing *parent = (cgns_governing *)posit->posit;
09700 if (strcmp(node_label,"Descriptor_t")==0) CGNS_DELETE_SHIFT(ndescr, descr)
09701 else if (strcmp(node_label,"UserDefinedData_t")==0) CGNS_DELETE_SHIFT(nuser_data, user_data)
09702 else if (strcmp(node_name,"DiffusionModel")==0) parent->diffusion_model=0;
09703
09704
09705 } else if (strcmp(posit->label,"GasModel_t")==0 ||
09706 strcmp(posit->label,"ViscosityModel_t")==0 ||
09707 strcmp(posit->label,"ThermalConductivityModel_t")==0 ||
09708 strcmp(posit->label,"TurbulenceModel_t")==0 ||
09709 strcmp(posit->label,"TurbulenceClosure_t")==0 ||
09710 strcmp(posit->label,"ThermalRelaxationModel_t")==0 ||
09711 strcmp(posit->label,"ChemicalKineticsModel_t")==0 ||
09712 strcmp(posit->label,"EMElectricFieldModel_t")==0 ||
09713 strcmp(posit->label,"EMMagneticFieldModel_t")==0 ||
09714 strcmp(posit->label,"EMConductivityModel_t")==0) {
09715 cgns_model *parent = (cgns_model *)posit->posit;
09716 if (strcmp(node_label,"Descriptor_t")==0) CGNS_DELETE_SHIFT(ndescr, descr)
09717 else if (strcmp(node_label,"UserDefinedData_t")==0) CGNS_DELETE_SHIFT(nuser_data, user_data)
09718 else if (strcmp(node_label,"DataArray_t")==0) CGNS_DELETE_SHIFT(narrays, array)
09719 else if (strcmp(node_name,"DataClass")==0) parent->data_class = DataClassNull;
09720 else if (strcmp(node_name,"DimensionalUnits")==0) parent->units=0;
09721 else if (strcmp(posit->label,"TurbulenceModel_t")==0 && strcmp(node_name,"DiffusionModel")==0)
09722 parent->diffusion_model=0;
09723
09724
09725 } else if (strcmp(posit->label,"ConvergenceHistory_t")==0) {
09726 cgns_converg *parent = (cgns_converg *)posit->posit;
09727 if (strcmp(node_name,"NormDefinitions")==0) parent->NormDefinitions=0;
09728 else if (strcmp(node_label,"Descriptor_t")==0) CGNS_DELETE_SHIFT(ndescr, descr)
09729 else if (strcmp(node_label,"UserDefinedData_t")==0) CGNS_DELETE_SHIFT(nuser_data, user_data)
09730 else if (strcmp(node_label,"DataArray_t")==0) CGNS_DELETE_SHIFT(narrays, array)
09731 else if (strcmp(node_name,"DataClass")==0) parent->data_class = DataClassNull;
09732 else if (strcmp(node_name,"DimensionalUnits")==0) parent->units=0;
09733
09734
09735 } else if (strcmp(posit->label,"IntegralData_t")==0) {
09736 cgns_integral *parent = (cgns_integral *)posit->posit;
09737 if (strcmp(node_label,"Descriptor_t")==0) CGNS_DELETE_SHIFT(ndescr, descr)
09738 else if (strcmp(node_label,"UserDefinedData_t")==0) CGNS_DELETE_SHIFT(nuser_data, user_data)
09739 else if (strcmp(node_label,"DataArray_t")==0) CGNS_DELETE_SHIFT(narrays, array)
09740 else if (strcmp(node_name,"DataClass")==0) parent->data_class = DataClassNull;
09741 else if (strcmp(node_name,"DimensionalUnits")==0) parent->units=0;
09742
09743
09744 } else if (strcmp(posit->label,"ReferenceState_t")==0) {
09745 cgns_state *parent = (cgns_state *)posit->posit;
09746 if (strcmp(node_name,"ReferenceStateDescription")==0) parent->StateDescription=0;
09747 else if (strcmp(node_label,"Descriptor_t")==0) CGNS_DELETE_SHIFT(ndescr, descr)
09748 else if (strcmp(node_label,"UserDefinedData_t")==0) CGNS_DELETE_SHIFT(nuser_data, user_data)
09749 else if (strcmp(node_label,"DataArray_t")==0) CGNS_DELETE_SHIFT(narrays, array)
09750 else if (strcmp(node_name,"DataClass")==0) parent->data_class = DataClassNull;
09751 else if (strcmp(node_name,"DimensionalUnits")==0) parent->units=0;
09752
09753
09754 } else if (strcmp(posit->label,"Family_t")==0) {
09755 cgns_family *parent = (cgns_family *)posit->posit;
09756 if (strcmp(node_label,"Descriptor_t")==0) CGNS_DELETE_SHIFT(ndescr, descr)
09757 else if (strcmp(node_label,"UserDefinedData_t")==0) CGNS_DELETE_SHIFT(nuser_data, user_data)
09758 else if (strcmp(node_label,"GeometryReference_t")==0) CGNS_DELETE_SHIFT(ngeos, geo)
09759 else if (strcmp(node_label,"FamilyBC_t")==0) CGNS_DELETE_SHIFT(nfambc, fambc)
09760 else if (strcmp(node_name,"Ordinal")==0) parent->ordinal=0;
09761 else if (strcmp(node_name,"RotatingCoordinates")==0) parent->rotating=0;
09762
09763 } else if (strcmp(posit->label,"FamilyBC_t")==0) {
09764 cgns_fambc *parent = (cgns_fambc *)posit->posit;
09765 if (strcmp(node_label,"BCDataSet_t")==0) CGNS_DELETE_SHIFT(ndataset, dataset)
09766
09767
09768 } else if (strcmp(posit->label,"GeometryReference_t")==0) {
09769 cgns_geo *parent = (cgns_geo *)posit->posit;
09770 if (strcmp(node_label,"Descriptor_t")==0) CGNS_DELETE_SHIFT(ndescr, descr)
09771 else if (strcmp(node_label,"UserDefinedData_t")==0) CGNS_DELETE_SHIFT(nuser_data, user_data)
09772 else if (strcmp(node_label,"GeometryEntity_t")==0) CGNS_DELETE_SHIFT(npart, part)
09773
09774
09775
09776 } else if (strcmp(posit->label,"Elements_t")==0) {
09777 cgns_section *parent = (cgns_section *)posit->posit;
09778 if (strcmp(node_label,"Descriptor_t")==0) CGNS_DELETE_SHIFT(ndescr, descr)
09779 else if (strcmp(node_label,"UserDefinedData_t")==0) CGNS_DELETE_SHIFT(nuser_data, user_data)
09780 else if (strcmp(node_name,"ParentData")==0) parent->parent=0;
09781
09782
09783
09784 } else if (strcmp(posit->label,"RigidGridMotion_t")==0) {
09785 cgns_rmotion *parent = (cgns_rmotion *)posit->posit;
09786 if (strcmp(node_label,"Descriptor_t")==0) CGNS_DELETE_SHIFT(ndescr, descr)
09787 else if (strcmp(node_label,"UserDefinedData_t")==0) CGNS_DELETE_SHIFT(nuser_data, user_data)
09788 else if (strcmp(node_label,"DataArray_t")==0) CGNS_DELETE_SHIFT(narrays, array)
09789 else if (strcmp(node_name,"DataClass")==0) parent->data_class = DataClassNull;
09790 else if (strcmp(node_name,"DimensionalUnits")==0) parent->units=0;
09791
09792
09793 } else if (strcmp(posit->label,"ArbitraryGridMotion_t")==0) {
09794 cgns_amotion *parent = (cgns_amotion *)posit->posit;
09795 if (strcmp(node_label,"Descriptor_t")==0) CGNS_DELETE_SHIFT(ndescr, descr)
09796 else if (strcmp(node_label,"UserDefinedData_t")==0) CGNS_DELETE_SHIFT(nuser_data, user_data)
09797 else if (strcmp(node_label,"DataArray_t")==0) CGNS_DELETE_SHIFT(narrays, array)
09798 else if (strcmp(node_name,"DataClass")==0) parent->data_class = DataClassNull;
09799 else if (strcmp(node_name,"DimensionalUnits")==0) parent->units=0;
09800 else if (strcmp(node_name,"GridLocation")==0) parent->location=GridLocationNull;
09801 else if (strcmp(node_name,"Rind")==0) {
09802 if (posit_base && posit_zone) {
09803 index_dim = cg->base[posit_base-1].zone[posit_zone-1].index_dim;
09804 } else {
09805 cgi_error("Can't find IndexDimension in cg_delete");
09806 return CG_NO_INDEX_DIM;
09807 }
09808 for (n=0; n<2*index_dim; n++) parent->rind_planes[n] = 0;
09809 }
09810
09811
09812 } else if (strcmp(posit->label,"BaseIterativeData_t")==0) {
09813 cgns_biter *parent = (cgns_biter *)posit->posit;
09814 if (strcmp(node_label,"Descriptor_t")==0) CGNS_DELETE_SHIFT(ndescr, descr)
09815 else if (strcmp(node_label,"UserDefinedData_t")==0) CGNS_DELETE_SHIFT(nuser_data, user_data)
09816 else if (strcmp(node_label,"DataArray_t")==0) CGNS_DELETE_SHIFT(narrays, array)
09817 else if (strcmp(node_name,"DataClass")==0) parent->data_class = DataClassNull;
09818 else if (strcmp(node_name,"DimensionalUnits")==0) parent->units=0;
09819
09820
09821 } else if (strcmp(posit->label,"ZoneIterativeData_t")==0) {
09822 cgns_ziter *parent = (cgns_ziter *)posit->posit;
09823 if (strcmp(node_label,"Descriptor_t")==0) CGNS_DELETE_SHIFT(ndescr, descr)
09824 else if (strcmp(node_label,"UserDefinedData_t")==0) CGNS_DELETE_SHIFT(nuser_data, user_data)
09825 else if (strcmp(node_label,"DataArray_t")==0) CGNS_DELETE_SHIFT(narrays, array)
09826 else if (strcmp(node_name,"DataClass")==0) parent->data_class = DataClassNull;
09827 else if (strcmp(node_name,"DimensionalUnits")==0) parent->units=0;
09828
09829
09830 } else if (strcmp(posit->label,"UserDefinedData_t")==0) {
09831 cgns_user_data *parent = (cgns_user_data *)posit->posit;
09832 if (strcmp(node_label,"Descriptor_t")==0) CGNS_DELETE_SHIFT(ndescr, descr)
09833 else if (strcmp(node_label,"DataArray_t")==0) CGNS_DELETE_SHIFT(narrays, array)
09834 else if (strcmp(node_name,"DataClass")==0) parent->data_class = DataClassNull;
09835 else if (strcmp(node_name,"DimensionalUnits")==0) parent->units=0;
09836 else if (strcmp(node_label,"UserDefinedData_t")==0) CGNS_DELETE_SHIFT(nuser_data, user_data)
09837 else if (strcmp(node_name,"GridLocation")==0) parent->location=GridLocationNull;
09838 else if (strcmp(node_name,"FamilyName")==0) parent->family_name[0]='\0';
09839 else if (strcmp(node_name,"Ordinal")==0) parent->ordinal=0;
09840
09841
09842
09843 } else if (strcmp(posit->label,"Gravity_t")==0) {
09844 cgns_gravity *parent = (cgns_gravity *)posit->posit;
09845 if (strcmp(node_label,"Descriptor_t")==0) CGNS_DELETE_SHIFT(ndescr, descr)
09846 else if (strcmp(node_label,"UserDefinedData_t")==0) CGNS_DELETE_SHIFT(nuser_data, user_data)
09847 else if (strcmp(node_name,"DataClass")==0) parent->data_class = DataClassNull;
09848 else if (strcmp(node_name,"DimensionalUnits")==0) parent->units=0;
09849
09850
09851 } else if (strcmp(posit->label,"Axisymmetry_t")==0) {
09852 cgns_axisym *parent = (cgns_axisym *)posit->posit;
09853 if (strcmp(node_label,"Descriptor_t")==0) CGNS_DELETE_SHIFT(ndescr, descr)
09854 else if (strcmp(node_label,"UserDefinedData_t")==0) CGNS_DELETE_SHIFT(nuser_data, user_data)
09855 else if (strcmp(node_label,"DataArray_t")==0) CGNS_DELETE_SHIFT(narrays, array)
09856 else if (strcmp(node_name,"DataClass")==0) parent->data_class = DataClassNull;
09857 else if (strcmp(node_name,"DimensionalUnits")==0) parent->units=0;
09858
09859
09860 } else if (strcmp(posit->label,"RotatingCoordinates_t")==0) {
09861 cgns_rotating *parent = (cgns_rotating *)posit->posit;
09862 if (strcmp(node_label,"Descriptor_t")==0) CGNS_DELETE_SHIFT(ndescr, descr)
09863 else if (strcmp(node_label,"UserDefinedData_t")==0) CGNS_DELETE_SHIFT(nuser_data, user_data)
09864 else if (strcmp(node_label,"DataArray_t")==0) CGNS_DELETE_SHIFT(narrays, array)
09865 else if (strcmp(node_name,"DataClass")==0) parent->data_class = DataClassNull;
09866 else if (strcmp(node_name,"DimensionalUnits")==0) parent->units=0;
09867
09868
09869 } else if (strcmp(posit->label,"BCProperty_t")==0) {
09870 cgns_bprop *parent = (cgns_bprop *)posit->posit;
09871 if (strcmp(node_label,"Descriptor_t")==0) CGNS_DELETE_SHIFT(ndescr, descr)
09872 else if (strcmp(node_label,"UserDefinedData_t")==0) CGNS_DELETE_SHIFT(nuser_data, user_data)
09873 else if (strcmp(node_name,"WallFunction")==0) parent->bcwall = 0;
09874 else if (strcmp(node_name,"Area")==0) parent->bcarea = 0;
09875
09876
09877 } else if (strcmp(posit->label,"WallFunction_t")==0) {
09878 cgns_bcwall *parent = (cgns_bcwall *)posit->posit;
09879 if (strcmp(node_label,"Descriptor_t")==0) CGNS_DELETE_SHIFT(ndescr, descr)
09880 else if (strcmp(node_label,"UserDefinedData_t")==0) CGNS_DELETE_SHIFT(nuser_data, user_data)
09881
09882
09883
09884 } else if (strcmp(posit->label,"Area_t")==0) {
09885 cgns_bcarea *parent = (cgns_bcarea *)posit->posit;
09886 if (strcmp(node_label,"Descriptor_t")==0) CGNS_DELETE_SHIFT(ndescr, descr)
09887 else if (strcmp(node_label,"UserDefinedData_t")==0) CGNS_DELETE_SHIFT(nuser_data, user_data)
09888
09889
09890
09891 } else if (strcmp(posit->label,"GridConnectivityProperty_t")==0) {
09892 cgns_cprop *parent = (cgns_cprop *)posit->posit;
09893 if (strcmp(node_label,"Descriptor_t")==0) CGNS_DELETE_SHIFT(ndescr, descr)
09894 else if (strcmp(node_label,"UserDefinedData_t")==0) CGNS_DELETE_SHIFT(nuser_data, user_data)
09895 else if (strcmp(node_name,"Periodic")==0) parent->cperio=0;
09896 else if (strcmp(node_name,"AverageInterface")==0) parent->caverage=0;
09897
09898
09899 } else if (strcmp(posit->label,"Periodic_t")==0) {
09900 cgns_cperio *parent = (cgns_cperio *)posit->posit;
09901 if (strcmp(node_label,"Descriptor_t")==0) CGNS_DELETE_SHIFT(ndescr, descr)
09902 else if (strcmp(node_label,"UserDefinedData_t")==0) CGNS_DELETE_SHIFT(nuser_data, user_data)
09903 else if (strcmp(node_name,"DataClass")==0) parent->data_class = DataClassNull;
09904 else if (strcmp(node_name,"DimensionalUnits")==0) parent->units=0;
09905
09906
09907
09908 } else if (strcmp(posit->label,"AverageInterface_t")==0) {
09909 cgns_caverage *parent = (cgns_caverage *)posit->posit;
09910 if (strcmp(node_label,"Descriptor_t")==0) CGNS_DELETE_SHIFT(ndescr, descr)
09911 else if (strcmp(node_label,"UserDefinedData_t")==0) CGNS_DELETE_SHIFT(nuser_data, user_data)
09912
09913
09914 } else {
09915 cgi_error("Unrecognized label: '%s'",posit->label);
09916 return CG_ERROR;
09917 }
09918 return CG_OK;
09919 }
09920
09921
09922
09923
09924
09925 int cg_free(void *data) {
09926 if (data != NULL) {
09927 CGNS_FREE (data);
09928 return CG_OK;
09929 }
09930 return CG_ERROR;
09931 }