First, let's set our resources in a local resource file which is specific to this application. Thus we will use the combination of NhlInitialize and an NhlCreate of an App object. We could also have chosen to use NhlOpen and set the resources in the file whose pathname is given by system variable $(NCARG_USRRESFILE). Or we could choose to set resources directly in the program using arguments in Create calls or by using the NhlSetValues functions.
We do not need a data object since TextItem does not import data. The text string to be written is merely entered as a resource.
Next, we need a workstation object in which to draw or write our graphical instructions. Suppose we just choose an X Window, which is an XWorkstation object.
Finally, we need a View object, namely TextItem.
Now that we know which objects we need, we can define the header files that are needed; these include:
Fortran:
external nhlfappclass external nhlfxworkstationclass external nhlftextitemclassApp, XWorkstation, and TextItem are the classes we are going to use in this program.
Fortran headers lists the headers for all objects.
Fortran:
call nhlfinitialize
Fortran:
call nhlfrlcreate(rlist,'setrl') call nhlfrlclear(rlist) call nhlfrlsetstring(rlist,'appDefaultParent','True',ierr) call nhlfrlsetstring(rlist,'appUsrDir','./',ierr) call nhlfcreate(appid,'tx01',nhlfappclass,0,rlist,ierr)This section of code
When we run this program, it will expect to find a resource file named tx01.res in the current working directory.
Fortran:
call nhlfrlclear(rlist) call nhlfrlsetstring(rlist,'wkPause','True',ierr) call nhlfcreate(wid,'tx01Work',nhlfxworkstationclass, $ 0,rlist,ierr)This section of code
Fortran:
call nhlfrlclear(rlist) call nhlfrlsetfloat(rlist,'txPosXF',.5,ierr) call nhlfrlsetfloat(rlist,'txPosYF',.5,ierr) call nhlfrlsetfloat(rlist,'txJust','CenterCenter',ierr) call nhlfcreate(pid,'TextItem1',nhlftextitemclass, $ wid,rlist,ierr)This section of code
Note: The resources could also be set in the resource file tx01.res.
Fortran:
call nhlfdraw(pid,ierr) or call nhlfdraw(wid,ierr) call nhlfframe(wid,ierr)The draw function causes the TextItem object, id = pid, to be drawn. The frame function flushes the output device. Since we set the NhlNwkPause XWorkstation resource to True, the plot will be drawn and held in the window awaiting a click in the window.
If you intend to continue the program and create some new and different App, Plot, or Workstation objects, and if you no longer need any of the current objects, then good programming practice is to delete the objects that are no longer required in order to keep the memory size of your program down. If you are about to end the program, go on to Step 9.
Fortran:
call nhlfdestroy(pid,ierr) call nhlfdestroy(wid,ierr) call nhlfdestroy(appid,ierr)
Fortran:
call nhlfclose stop endThis section of code destroys all existing objects, closes the HLU library, and exits our program.
First, let's set our resources in a local resource file which is specific to this application. Thus we will use the combination of NhlInitialize and an NhlCreate of an App object. We could also have chosen to use NhlOpen and set the resources in the file whose pathname is given by the environment variable $(NCARG_USRRESFILE). Or we could choose to set resources directly in the program using resource list arguments in Create calls or by using the NhlSetValues functions.
We do not need a data object since TextItem does not import data. The text string to be written is merely entered as a resource.
Next, we need a workstation object in which to draw or write our graphical instructions. Suppose we just choose an X Window, which is an XWorkstation object.
Finally, we need a View object, namely TextItem.
Now that we know which objects we need, we can define the header files that are needed; these include:
C:
#include <ncarg/hlu/App.h> #include <ncarg/hlu/TextItem.h> #include <ncarg/hlu/XWorkstation.h>App, XWorkstation, and TextItem are the objects we are going to use in this program.
C headers lists the headers for all objects.
C:
NhlInitialize();
C:
rlist = NhlRLCreate(NhlSETRL); NhlRLClear(rlist); NhlRLSetString(rlist,NhlNappDefaultParent,"True"); NhlRLSetString(rlist,NhlNappUsrDir,"./"); NhlCreate(&appid,"tx01",NhlappClass,NhlDEFAULT_APP,rlist);This section of code
When we run this program, it will expect to find a resource file named tx01.res in the working directory.
C:
NhlRLClear(rlist); NhlRLSetInteger(rlist,NhlNwkPause,True); NhlCreate(&wid,"txxwork",NhlxWorkstationClass,NhlDEFAULT.APP,rlist);This section of code
C:
NhlRLClear(rlist); NhlRLSetFloat(rlist,NhlNtxPosXF,.2); NhlRLSetFloat(rlist,NhlNtxPosYF,.8); NhlRLSetInteger(rlist,NhlNtxJust,NhlCENTERCENTER); NhlCreate(&pid,"TextItem1", NhltextItemClass,wid,rlist);This section of code
Note: The resources could also be set in the resource file tx01.res.
C:
NhlDraw(pid); NhlFrame(wid);The draw function causes the TextItem object, id = pid, to be drawn. The frame function flushes the output device. Since we set the NhlNwkPause XWorkstation resource to True, the plot will be drawn and held in the window awaiting a click in the window.
If you intend to continue the program and create some new and different App, Plot, or Workstation objects, and if you no longer need any of the current objects, then good programming practice is to delete the objects that are no longer required in order to keep the memory size of your program down. If you are about to end the program, go on to Step 9.
C:
NhlDestroy(pid); NhlDestroy(wid); NhlDestroy(appid);
Or you could just destroy the App object since it is the ancestor of the other objects; this will cause all of its children to be destroyed as well. (This is also why the destroy calls above must be in the order in which they appear.)
C:
NhlDestroy(appid);
C:
NhlClose(); exit(0);This section of code destroys all existing objects, closes the HLU library, and exits our program.
ng4ex tx01cfor the C version, or
ng4ex tx01ffor the Fortran version.
Either of the ng4ex commands above will also load tx01.res into your working directory.
ng4ex xy01cfor the C version, or
ng4ex xy01ffor the Fortran version.
NG4.1 Home, Index, Examples, Glossary, Feedback, UG Contents, UG WhereAmI?