NCstate NCdsHandleVPointDefine(NCdsHandleVPoint_t *point, int ncid) { if (NCdataGetType(ncid) != NCtypePoint) { CMmsgPrint(CMmsgAppError, "Invalid point data in: %s %d", __FILE__, __LINE__); return (NCfailed); } if (NCdsHandleVectorDefine((NCdsHandleVector_t *) point, ncid) == NCfailed) { NCdsHandleVectorClear((NCdsHandleVector_t *) point); return (NCfailed); } point->XCoords = point->YCoords = (double *) NULL; if ((point->XCoords = (double *) calloc(point->ItemNum, sizeof(double))) == (double *) NULL) { CMmsgPrint(CMmsgSysError, "Memory allocation error in: %s %d", __FILE__, __LINE__); NCdsHandleVectorClear((NCdsHandleVector_t *) point); return (NCfailed); } if ((point->YCoords = (double *) calloc(point->ItemNum, sizeof(double))) == (double *) NULL) { CMmsgPrint(CMmsgSysError, "Memory allocation error in: %s %d", __FILE__, __LINE__); free(point->XCoords); NCdsHandleVectorClear((NCdsHandleVector_t *) point); return (NCfailed); } return (NCsucceeded); }
NCdsHandle_t *NCdsHandleOpenByIds (int *ncids, size_t n) { int ret; NCdsHandle_t *dsHandle = (NCdsHandle_t *) NULL; NCdataType dataType; if (n < 1) return ((NCdsHandle_t *) NULL); switch (dataType = NCdataGetType (ncids [0])) { default: CMmsgPrint (CMmsgAppError, "Invalid data type in: %s %d",__FILE__,__LINE__); return ((NCdsHandle_t *) NULL); case NCtypeGCont: dsHandle = (NCdsHandle_t *) malloc (sizeof (NCdsHandleGCont_t)); break; // case NCtypeGDisc: dsHandle = (NCdsHandle_t *) malloc (sizeof (NCdsHandleGDisc_t)); break; case NCtypeNetwork: dsHandle = (NCdsHandle_t *) malloc (sizeof (NCdsHandleNetwork_t)); break; case NCtypePoint: dsHandle = (NCdsHandle_t *) malloc (sizeof (NCdsHandleVPoint_t)); break; // case NCtypeLine: dsHandle = (NCdsHandle_t *) malloc (sizeof (NCdsHandleVLine_t)); break; // case NCtypePolygon: dsHandle = (NCdsHandle_t *) malloc (sizeof (NCdsHandleVPolygon_t)); break; } if (dsHandle == (NCdsHandle_t *) NULL) { CMmsgPrint (CMmsgAppError, "Memory allocation error in: %s %d",__FILE__,__LINE__); return ((NCdsHandle_t *) NULL); } switch (dataType) { default: free (dsHandle); return ((NCdsHandle_t *) NULL); case NCtypeGCont: ret = NCdsHandleGContDefine ((NCdsHandleGCont_t *) dsHandle, ncids, n); break; // case NCtypeGDisc: ret = NCdsHandleGDiscDefine ((NCdsHandleGDisc_t *) dsHandle, ncids, n); break; case NCtypeNetwork: ret = NCdsHandleNetworkDefine ((NCdsHandleNetwork_t *) dsHandle, ncids [0]); break; case NCtypePoint: ret = NCdsHandleVPointDefine ((NCdsHandleVPoint_t *) dsHandle, ncids [0]); break; // case NCtypeLine: ret = NCdsHandleVLineDefine ((NCdsHandleVLine_t *) dsHandle, ncids [0]); break; // case NCtypePolygon: ret = NCdsHandleVPolygonDefine ((NCdsHandleVPolygon_t *) dsHandle, ncids [0]); break; } if (ret == NCfailed) return ((NCdsHandle_t *) NULL); return (dsHandle); }
NCstate NCdsHandleNetworkDefine(NCdsHandleNetwork_t *net, int ncid) { int status; if (NCdataGetType(ncid) != NCtypeNetwork) { CMmsgPrint(CMmsgAppError, "Invalid network in: %s %d", __FILE__, __LINE__); return (NCfailed); } if (NCdsHandleGLayoutDefine((NCdsHandleGLayout_t *) net, &ncid, 1) == NCfailed) return (NCfailed); net->Data = (int *) NULL; net->Basins.Table = net->Cells.Table = (NCtable_t *) NULL; if ((net->Data = (int *) calloc(net->ColNum * net->RowNum, sizeof(int))) == (int *) NULL) { CMmsgPrint(CMmsgSysError, "Memory allocation error in: %s %d", __FILE__, __LINE__); NCdsHandleNetworkClear(net); return (NCfailed); } if ((status = nc_get_var_int(ncid, net->GVarIds[0], net->Data)) != NC_NOERR) { NCprintNCError (status, "NCdsHandleNetworkDefine"); NCdsHandleNetworkClear(net); return (NCfailed); } if ((net->Basins.Table = NCtableOpen(ncid, NCnameTBItems)) == (NCtable_t *) NULL) { NCdsHandleNetworkClear(net); return (NCfailed); } if ((net->Cells.Table = NCtableOpen(ncid, NCnameTBCells)) == (NCtable_t *) NULL) { NCdsHandleNetworkClear(net); return (NCfailed); } if (((net->Basins.NameFld = NCtableGetFieldByName(net->Basins.Table, NCnameTBItems)) == (NCfield_t *) NULL) || ((net->Basins.RowFld = NCtableGetFieldByName(net->Basins.Table, NCnameBSNRow)) == (NCfield_t *) NULL) || ((net->Basins.ColFld = NCtableGetFieldByName(net->Basins.Table, NCnameBSNCol)) == (NCfield_t *) NULL) || ((net->Basins.OrderFld = NCtableGetFieldByName(net->Basins.Table, NCnameBSNOrder)) == (NCfield_t *) NULL) || ((net->Basins.SymbolFld = NCtableGetFieldByName(net->Basins.Table, NCnameBSNSymbol)) == (NCfield_t *) NULL) || ((net->Basins.LengthFld = NCtableGetFieldByName(net->Basins.Table, NCnameBSNLength)) == (NCfield_t *) NULL) || ((net->Basins.AreaFld = NCtableGetFieldByName(net->Basins.Table, NCnameBSNArea)) == (NCfield_t *) NULL) || ((net->Cells.RowFld = NCtableGetFieldByName(net->Cells.Table, NCnameCLSRow)) == (NCfield_t *) NULL) || ((net->Cells.ColFld = NCtableGetFieldByName(net->Cells.Table, NCnameCLSCol)) == (NCfield_t *) NULL) || ((net->Cells.ToCellFld = NCtableGetFieldByName(net->Cells.Table, NCnameCLSToCell)) == (NCfield_t *) NULL) || ((net->Cells.FromCellFld = NCtableGetFieldByName(net->Cells.Table, NCnameCLSFromCell)) == (NCfield_t *) NULL) || ((net->Cells.BasinFld = NCtableGetFieldByName(net->Cells.Table, NCnameCLSBasinId)) == (NCfield_t *) NULL) || ((net->Cells.NCellsFld = NCtableGetFieldByName(net->Cells.Table, NCnameCLSNCells)) == (NCfield_t *) NULL) || ((net->Cells.TravelFld = NCtableGetFieldByName(net->Cells.Table, NCnameCLSTravel)) == (NCfield_t *) NULL) || ((net->Cells.OrderFld = NCtableGetFieldByName(net->Cells.Table, NCnameCLSOrder)) == (NCfield_t *) NULL) || ((net->Cells.LengthFld = NCtableGetFieldByName(net->Cells.Table, NCnameCLSLength)) == (NCfield_t *) NULL) || ((net->Cells.AreaFld = NCtableGetFieldByName(net->Cells.Table, NCnameCLSArea)) == (NCfield_t *) NULL)) { CMmsgPrint(CMmsgAppError, "Corrupt networkd data in: %s %d", __FILE__, __LINE__); NCdsHandleNetworkClear(net); return (NCfailed); } return (NCsucceeded); }
NCstate NCdsHandleDefine (NCdsHandle_t *dsh, int *ncids, size_t n) { NCdataType dataType; int i; dsh->NCIds = (int *) NULL; NCdsHandleClear (dsh); if (n < 1) return (NCfailed); if ((dataType = NCdataGetType (ncids [0])) == NCtypeUndefined) return (NCfailed); dsh->DataType = dataType; if ((dsh->NCIds = (int *) calloc (n,sizeof (int))) == (int *) NULL) { CMmsgPrint (CMmsgSysError, "Memory allocation error in: %s %d",__FILE__,__LINE__); return (NCfailed); } for (i = 0;i < n;++i) dsh->NCIds [i] = ncids [i]; dsh->NCnum = n; return (NCsucceeded); }