Data classes are any of the classes that are used to provide user input data to any of the objects that utilize such data. Included are the CoordArrays class, the CoordArrTable class, the ScalarField class, and the VectorField class.
StreamlinePlot, VectorPlot, XyPlot, and ContourPlot are View classes that require an input data class.
Creating a data object and linking it to a view object is a two-step process. Examples for one-dimensional data to be used in an XyPlot and a two-dimensional field to be used in a ContourPlot are shown below in both C and Fortran.
Create a data object by assigning data values using the caXArray and caYArray resources of the CoordArrays class.
The CoordArrays data class is used for bringing one-dimensional data curves into an XyPlot object in a Fortran HLU program. The set of Y values for the curve is defined by the caYArray resource. The set of X values of the curve can be explicitly set in the caXArray resource, or can implicitly default to the point number if not set as a caXArray resource.
C C Create the dataid object after assigning n values of the temp array C to the caYArray resource, and n values of the time array to caXArray. C call NhlFRLClear(rlist) call NhlFRLSetFloatArray(rlist,'caXArray',time,n,ierr) call NhlFRLSetFloatArray(rlist,'caYArray',temp,n,ierr) call NhlFCreate(dataid,'xyData',NhlFCoordArraysClass,0, + rlist,ierr)
If the resource caXArray is not explicitly set, as done above, it will default to a set of integers from 1 to n.
NhlRLClear(rlist); NhlRLSetFloatArray(rlist,NhlNcaYArray,(float *)temp,n); NhlRLSetFloatArray(rlist,NhlNcaYArray,(float *)time,n); NhlCreate(&dataid,"xyData",NhlcoordArraysClass, NhlDEFAULT_APP,rlist);
Create an XyPlot object using the xyCoordData resource to connect the data object, dataid, to the XyPlot object, plotid.
C C The id for this dummy data object will now become the resource C value for "xyCoordData". C call NhlFRLClear(rlist) call NhlFRLSetInteger(rlist,'xyCoordData',dataid,ierr) call NhlFCreate(plotid,'xyPlot1',NhlFXyPlotClass,xworkid, + rlist,ierr)
/* * The id from this dummy data object will now become the resource * value for "xyCoordData". */ NhlRLClear(rlist); NhlRLSetInteger(rlist,NhlNxyCoordData,dataid); NhlCreate(&plotid,"xyPlot1",NhlxyPlotClass,xworkid,rlist);
xy06f.f and xy06c.c are examples that show the input and display of several datasets using CoordArrays and XyPlot objects.
The data class CoordArrTable can also be used for creating one-dimensional data objects. It is especially useful for creating plots with multiple curves, where each curve can have a different number of points. Consider the following C code segment from the example program, xy05c.c. It shows setting the CoordArrTable resources ctYTable and ctYTableLengths. There are NCURVE curves of possibly varying lengths equal to length(1), length(2), ..., length(NCURVE). The data values all reside in array y, with pointers defined for each of the NCURVE curves.
/* * Create the CoordArrTable object which defines the data for the * XyPlot object. The id from this object will become the value for * the XyPlot resource, "xyCoordData". */ NhlRLClear(rlist); NhlRLSetIntegerArray(rlist,NhlNctYTableLengths,length,NCURVE); NhlRLSetArray(rlist,NhlNctYTable,y,NhlTPointer,sizeof(NhlPointer), NCURVE); NhlCreate(&dataid,"xyData",NhlcoordArrTableClass, NhlDEFAULT_APP,rlist); /* * Create the XyPlot object and identify the xyCoordData resource as * the data object, dataid. */ NhlRLClear(rlist); NhlRLSetInteger(rlist,NhlNxyCoordData,dataid); NhlCreate(&plotid,"xyPlot",NhlxyPlotClass,xworkid,rlist);
The ScalarField data object is used to pass two-dimensional datasets to a ContourPlot object. Sample Fortran and C codes are given below.
C C Assign the two-dimensional data array z(N,M) to the sfDataArray resource, C and create a ScalarField data object. C call NhlFRLClear(rlist) len_dims(1) = N len_dims(2) = M call NhlFRLSetmdfloatarray(rlist,'sfDataArray',z,2,len_dims,ierr) call NhlFCreate(dataid,'Gendat',nhlfscalarfieldclass,appid, 1 rlist,ierr) C C Create a ContourPlot object, supplying the ScalarField object as data. C call NhlFRLClear(rlist) call NhlFRLSetinteger(rlist,'cnScalarFieldData',dataid,ierr) call NhlFCreate(cnid,'ContourPlot1',nhlfcontourplotclass, 1 wid,rlist,ierr)
/* * Assign the two-dimensional data array z(N,M) to the sfDataArray resource, * and create a ScalarField data object. */ NhlRLClear(rlist); len_dims[0] = N; len_dims[1] = M; NhlRLSetMDFloatArray(rlist,NhlNsfDataArray,z,2,len_dims); NhlCreate(&dataid,"Gendat",NhlscalarFieldClass,appid,rlist); /* * Create a ContourPlot object, supplying the ScalarField object as data. */ NhlRLClear(rlist); NhlRLSetInteger(rlist,NhlNcnScalarFieldData,dataid); NhlCreate(&cnid,"ContourPlot1",NhlcontourPlotClass,wid,rlist);
cn04f.f and cn04c.c are examples that show the use of ScalarField and ContourPlot objects.
NG4.1 Home, Index, Examples, Glossary, Feedback, UG Contents, UG WhereAmI?