/*NOTE: There is some bug in motif, so that Cascade buttons sometimes
    call the same program twice.  I do not think it causes an major 
   problems, but for some things - this may take some time. I have solved
   it (e.g. in setminden) by simply checking if value has changed and
   calling routine, only if it has. May need to do this in other routines
*/

#include "drawwindow.h"  // also calls global.h
#include "screen.h"
#include "mapmenu.h"
#include "menu.h"
//#include "core.h"
#include "bone.h"
#include "trace.h"
#include "math.h"
#include "peptide.h"
#include "extendfit.h"
#include "editbones.h"
#include "control.h"
#include "symmate.h"
#include "pdbtolev.h"
#include "assignseq.h"
#include "rankside.h"
#include "combine.h"
#include "selenomet.h"
#include "initialize.h"

extern struct maiddatafile maidfile;//Global variable - I do not know how to pass to menus
extern struct griddata map[NMAPS]; // all the map (denfile),contour data associated with map
extern struct coredata core[NMAPS];
extern struct bonedata bone[NMAPS];
extern struct pepset fitset;
extern struct screenvalue  sc;
extern struct extbones ext; // All the data for edited bones used to extend one end of a given fit
extern Widget toplevel;
extern struct geometry geo;
extern float fminden[10];
extern  struct st ss;  // Define before in menu.c++
extern struct rotomer rot[30];// rotomer data for each amino acid
extern int verbose; //Defined in trace.c++  if = 1, print a lot of stuff
Widget  mapmenu; // Global since needed in map_cb



float fcontradius[10]= { 5.0,7.5, 10.0,12.5,15,17.5,20};
float fcontlevel[10]= {0.5,1.0,1.5,2.0,2.5,3.0,3.5,4.0,5.0,6.0};


static void inputbone_ok_pushed(Widget w,XtPointer  client_data,XtPointer  call_data)
/* New on 17jun99  - input bone # - draw large X in White
*/
{
    printf(" OK pushed\n");
    char* text[5];
    int bonen;
    int totnum = bone[1].ptv.end()-bone[1].ptv.begin();

    text[0] =   XmTextFieldGetString (ss.w[0]);
    bonen = atoi(text[0]);
    printf(" Input bone num = %d\n",bonen);
    if( (bonen <= totnum)&&(bonen>=0) ){ // if  text[0]==null , fitnum = 0       
        sc.pickbone=1;
        bone[1].pickbone = bonen;
    }
    Widget shell = (Widget) client_data;
    XtDestroyWidget (shell);
}

static void inputfitnum_ok_pushed(Widget w,XtPointer  client_data,XtPointer  call_data)
/* New on 17jun99  - input bone # - draw large X in White
*/
{
    printf(" OK pushed\n");
    char* text[5];
    int totnum = bone[1].ptv.end()-bone[1].ptv.begin();
//    int foundedit;

    text[0] =   XmTextFieldGetString (ss.w[0]);
    geo.fitn = atoi(text[0]);
    printf(" Input fit num = %d\n",geo.fitn);
    ext.metend = -1;  // default - Normal case
#if 0 //Test finding selenomet positons
   int nsel,intnum;
   float selpos[MAXSEL][3];
   findselpos(map[1],"shad.maidselenomet",&intnum,&nsel,selpos);
#endif
#if 0 //Test gap assignment for all fits
    testgap(map[1],geo);
#endif
#if 0 //Combine several fit file
     combine(map[1],geo,"combinefile2");
#endif
#if 0 //Expand fits to sym. related fits and then assigns segment
//   expand(map[1],geo,"combinefile");
//   expand(map[1],geo,"fit.27jul00");
   expand(map[1],geo,maidfile.fitfile);
   assignseqment(map[1],geo,"expand");
#endif
#if 0// Check the second part of expand - apply rot/tran operators to all fits
float brot[NSYM][3][3],btran[NSYM][3];
int nsym,del[MAXDEL];
  del[0]=0; // keeps track of fits that should be deleted
    readfit(geo,"mtpk.maidfit");
   readnsym(maidfile.nsym,&nsym,brot,btran); // read rot/tran operators
   applyrottran(geo,map[1],nsym,brot,btran,del); // Apply rot/tran opertors to each fit, save if in good density - fuse and find del[]
#endif
#if 0//Test routine for assigning seqment number
int iselect,del[5];
del[0]=0;
//    readfit(geo,"tempfile3");
//    readfit(geo,"fit_refine.21aug00");
//    readfit(geo,"shad_ncs.10nov00");
    readfit(geo,"mtpk.maidfit");
//  iselect=1; // check for identical assigned fits
//  iselect=2; // check for identical assigned and unassighed fits
  iselect=0; // do all checks
//  removebadfits(iselect,map[1],geo);
//    removeonebadfit(130,iselect,map[1],geo,del,1);// 1=ifit = fit # that new fit was made from f by symop  - checks last added fit = 130 =fitnum[0] for bad fit
assignseqment(map[1],geo,"expand");
#endif
#if 0 // USED to find rotation pdb - choose ifit in pdb 1, ufit in region wnt
//          rotated pdb - and in symfit() or symfitass() - comment in just this ufit.
   int isym[NSYM][2],icheck,ifit,ifind,del[5],nsym,iplus;
   float brot[NSYM][3][3],btran[NSYM][3];
   icheck = 0; // This means do not check files in symfit
//   ifind = 1; // quit after find first sym mate and return best rotation matrix
   ifind = 0; // find all symmates - used when calling from extendfit
   ifit = 1; // Used to test file shad_testsym fit 17 res1 =  fit[14] res 1 
   printf("TTESTING SYMFIT\n");
//   iplus = 1; // Means try only  ufits >i, prevents duplication
   iplus = 0; // Means try all fits
   symfit(iplus,&ifind,icheck,geo,map[1],ifit,isym,&nsym,brot,btran,del);
//   symfitass(iplus,&ifind,icheck,geo,map[1],ifit,isym,&nsym,brot,btran,del); // check assigned fit
   savensym(maidfile.nsym,nsym,brot,btran);
#endif
#if 0 // test symfit and rank
   int isym[NSYM][2],icheck,ifit,ifind,del[5],iplus;
   float brot[3][3],btran[3];
     readfit(geo,"tempfit1");
     ifit = 6;
     ifind = 0;
     icheck = 0;
    iplus = 1; // Means try only  ufits >i, prevents duplication
     symfit(iplus,&ifind,icheck,geo,map[1],ifit,isym,brot,btran,del);
     readfit(geo,"tempfit2");
     ifit = 9;
    symfit(iplus,&ifind,icheck,geo,map[1],ifit,isym,brot,btran);
#endif
#if 0 //NOTE must readfit before calling builds and refines sequence if fit.val1 is assigned
 int ifit;
   verbose=2;
   readsequence(geo,maidfile.pdbsequence);
   ifit = 6;
   buildandrefineseq(map[1],geo,rot,ifit);
#endif
#if 0 //This call is the complete business- edits bones and extends to fit 
//    float fusedata[2];
    if(geo.fitn == 0) // this tries to extend all fits
        extendandfusebatch(fitset,map[1],geo);
    else  // just extend geo.fitn
        extendandfusebatch(fitset,map[1],geo);
#endif
#if 0   // for debugging if fit is very close to another fit
  ext.metend = 12;
#endif
#if 1 // This call just makes best edited bones 
int ibestden,foundedit;
     callbatchextend(map[1],geo,&foundedit,&ibestden); // 0 means readfitfile when called
#endif
#if 0 //This call refines the final edited bones
    int icontrol = 3; // 1 rebuild, 2 refine with diamond, 3 both
    rerefine(icontrol,map[1],geo);
#endif
#if 0  // Try to find missed fits using lower criteria
   retrace(map[1],geo,bone[1]);
#endif
    Widget shell = (Widget) client_data;
    XtDestroyWidget (shell);
}

void inputfitnum_dialog(Widget w)  // Dialog for inputting fit #
{
    Widget dialog, rc;
    XmString string;
    Arg args[5];
    int n = 0;
    static ActionAreaItem action_items[] = {
        { "OK",     inputfitnum_ok_pushed,     NULL          },
        { "Clear",  clear_pushed,  NULL          },
        { "Cancel", close_dialog,  NULL          },
        { "Help",   help,          "Help Button" },
    };
    /* Create a TemplateDialog that will contain the control area
     * and the action area buttons for the dialog
     */ 
    string = XmStringCreateLocalized ("Dialog Shell");
    XtSetArg (args[n], XmNdialogTitle, string); n++;
    XtSetArg (args[n], XmNautoUnmanage, False); n++;
    dialog = XmCreateTemplateDialog (toplevel, "dialog", args, n);
    XmStringFree (string);

    /* now that the dialog is created, set the Cancel button's
     * client data, so close_dialog() will know what to destroy.
     */
    action_items[0].data=action_items[2].data = (XtPointer) dialog;

    /* create the control area which contains a
     * Label gadget and a TextField widget.
     */
    rc = XtVaCreateWidget ("control_area", 
        xmRowColumnWidgetClass, dialog, NULL);
    ss.num = 1;
    string = XmStringCreateLocalized ("ENTER FIT #:");
    XtVaCreateManagedWidget ("label", xmLabelGadgetClass, rc,
        XmNlabelString,    string,
        NULL);
    XmStringFree (string);
    ss.w[0] = XtVaCreateManagedWidget ("text-field",xmTextFieldWidgetClass, rc, NULL);
   /* RowColumn is full -- now manage */
    XtManageChild (rc);
  
    /* Create the action area. */
    CreateActionArea (dialog, action_items, XtNumber (action_items));

    /* callback for Return in TextField.  Use dialog as client data */
//    XtAddCallback (ss.w[0], XmNactivateCallback,activate_cb, dialog);

    XtManageChild (dialog);
    XtPopup (XtParent (dialog), XtGrabNone);
    glClearColor(backcolv[0],backcolv[1],backcolv[2],0);//background color :red, green, blue, and alpha = black
}


void inputbone_dialog(Widget w)  // Dialog for inputting fit #
{
    Widget dialog, rc;
    XmString string;
    Arg args[5];
    int n = 0;
    static ActionAreaItem action_items[] = {
        { "OK",     inputbone_ok_pushed,     NULL          },
        { "Clear",  clear_pushed,  NULL          },
        { "Cancel", close_dialog,  NULL          },
        { "Help",   help,          "Help Button" },
    };
    /* Create a TemplateDialog that will contain the control area
     * and the action area buttons for the dialog
     */ 
    string = XmStringCreateLocalized ("Dialog Shell");
    XtSetArg (args[n], XmNdialogTitle, string); n++;
    XtSetArg (args[n], XmNautoUnmanage, False); n++;
    dialog = XmCreateTemplateDialog (toplevel, "dialog", args, n);
    XmStringFree (string);

    /* now that the dialog is created, set the Cancel button's
     * client data, so close_dialog() will know what to destroy.
     */
    action_items[0].data=action_items[2].data = (XtPointer) dialog;

    /* create the control area which contains a
     * Label gadget and a TextField widget.
     */
    rc = XtVaCreateWidget ("control_area", 
        xmRowColumnWidgetClass, dialog, NULL);
    ss.num = 1;
    string = XmStringCreateLocalized ("ENTER BONE #:");
    XtVaCreateManagedWidget ("label", xmLabelGadgetClass, rc,
        XmNlabelString,    string,
        NULL);
    XmStringFree (string);
    ss.w[0] = XtVaCreateManagedWidget ("text-field",xmTextFieldWidgetClass, rc, NULL);
   /* RowColumn is full -- now manage */
    XtManageChild (rc);
  
    /* Create the action area. */
    CreateActionArea (dialog, action_items, XtNumber (action_items));

    /* callback for Return in TextField.  Use dialog as client data */
//    XtAddCallback (ss.w[0], XmNactivateCallback,activate_cb, dialog);

    XtManageChild (dialog);
    XtPopup (XtParent (dialog), XtGrabNone);
    glClearColor(backcolv[0],backcolv[1],backcolv[2],0);//background color :red, green, blue, and alpha = black
}


void bonerad_cb(Widget widget,XtPointer client_data,XtPointer  call_data)
// Use some same functions as contour radius
{
    int item_no = (int) client_data;
    sc.boneradius2 = sqr(fcontradius[item_no]);  // Default bone radius squared
printf("Setting boneradius2 = %f\n",sc.boneradius2);
}   

void map_cb(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
printf("in map_cb  item_no = %d\n",item_no);
    if(item_no==6) // turn contour on off for all maps
       sc.drawcontour = -sc.drawcontour; // Turn on/off drawing of contour
    if(item_no==8){ // Turn on/off drawing of contour
       sc.draweditbones = -sc.draweditbones;
       if(sc.draweditbones ==1)
          readeditbones(maidfile.editbones); // read the saved edited bones
    } 
    if(item_no==9){ // Input and highlight a bone ON?OFF
      if(sc.pickbone == -1){
         sc.pickbone = 1;
         inputbone_dialog(toplevel);
       }
       else
          sc.pickbone = -1;
   }
   if(item_no==10) // Input geo.fitn 
         inputfitnum_dialog(toplevel);
   if(item_no==11){ // Write bones in sheres as pdb file
      writebonetopdb(map[1],geo,bone[1]);
      errormessage(toplevel,"BONES IN SPHERE WRITTEN TO FILE 'bone.pdb'");
   }
}

void centerbones(griddata& map1,bonedata& bone1)
{
  int ivec[3],i,k;  
  float fvec[3],xmin[3],xmax[3];

  printf("Centering using bones\n");
              for(k=0;k<=2;k++){// find min/max
                xmin[k] = 10000000.0;
                xmax [k]= -1000000.0;
              }
              int totnum = bone[1].ptv.end()-bone[1].ptv.begin();
              for(i=0;i<totnum;++i){   
                d1tod3(bone1.cmax,bone1.ptv[i].pos,ivec);
                imcv(map1,ivec,fvec);// convert int grid ivec to float world co-ord fvec
                for(k=0;k<=2;k++){// find min/max
                  if(fvec[k]<xmin[k])
                     xmin[k] = fvec[k];
                  if(fvec[k]> xmax[k])
                     xmax[k] = fvec[k];
                }
              }// i
              for(k=0;k<=2;k++)
                 sc.centerpos[k] = (xmin[k]+xmax[k])/2.0;
              sc.cmmaxh=2.0*(xmax[1]-xmin[1]);//  Maximum hight of visualized object
              sc.degfovy = sc.mag*(180.0/PI)*2.0*asin(sc.cmmaxh/(2.0*sc.cmeyedist));
printf("centerpos = %5.3f %5.3f %5.3f\n",sc.centerpos[0],sc.centerpos[1],sc.centerpos[2]);
printf("sc.cmmaxh = %5.3f   sc.degfovy= %5.3f\n",sc.cmmaxh,sc.degfovy);
              sc.run_wpid = XtAppAddWorkProc(sc.appctx,draw_screen,&sc.drawwind1);//This draw screen one time
              for(i=0;i<=2;i++){ // set rotation and translation back to 0
                  sc.rot[i] = sc.trans[i]=0;
              }
              maidfile.start = -1;
}

void setmapsub(int item_no,griddata& map1,bonedata& bone1)
/* this is also called from setminden
      bone.iexist = 6 indicates find new bones but do not write new maidfile
*/
{
  int i;
  char ch[20]; 
  FILE *fp;

printf("In setmapsub  item_no = %d\n",item_no);
   switch(item_no){
      case(0): // Turn contour on/off
         map1.contonoff  = -map1.contonoff;
         break;
      case(1): // Turn bone on/off _NOTE: something wrong with iexist - check if file exist each time
         if( (bone1.iexist == 0)||(bone1.iexist == 6)  ){ // bonefile does not exist = must create
//   bone1.minden = 1.6;  //Default minimum value  - NOW defined in initialize.c++
#if 1
           strcpy(bone1.bonename,map1.mapname);
           strcat(bone1.bonename,".bone"); // bone  name is mapname with .bone_minden appended
           sprintf(ch,"%1.1f",bone1.minden);
           strcat(bone1.bonename,ch);
//           fp=fopen(bone1.bonename,"r");
           if( (fp=fopen(bone1.bonename,"r")) == NULL){
               findbone(map1,bone1);
           }
           else{
               fclose(fp);
               readbonefile(bone1);
           }
#endif
           for(i=0;i<=2;i++){ // This overwrites colors in bonefile
              bone1.mcolor[i]=magentav[i];
              bone1.scolor[i]=cyanv[i];
           }
//           findbone(sc,map1,bone1);

           if(bone1.iexist == 0)
              writemaidfile(0,maidfile,map,bone); //"0" indicates use old file names rewrite maidfile with new bonename
           bone1.iexist =2; // Indicates bone read and ready to draw
         }
         else if(bone1.iexist ==1){ // bonefile exist but not read
           if( (fp=fopen(bone1.bonename,"r")) == NULL){
               findbone(map1,bone1);
           }
           else{
               fclose(fp);
               readbonefile(bone1);
           }
           for(i=0;i<=2;i++){ // This overwrites colors in bonefile
              bone1.mcolor[i]=magentav[i];
              bone1.scolor[i]=cyanv[i];
           }
           bone1.iexist =2; // Indicates bone read and ready to draw
         }
         else if(bone1.iexist ==2) { // On, turn off
            bone1.iexist = -2;
         }
         else if(bone1.iexist == -2) {// Off, turn on
            bone1.iexist = 2;
            for(i=0;i<=2;i++){ // Redefine - bacause may have read bones, but not colors
              bone1.mcolor[i]=magentav[i];
              bone1.scolor[i]=cyanv[i];
           }
         }
        if(maidfile.start>=0){ // First time  and pdb not read Center about first bone file  bones center 
                  centerbones(map1, bone1);
                  maidfile.start = -1;
        }
        break;
   }
}

void setcontrad(int item_no,griddata& map)
{
  int i;
     for(i=0;i<3;i++)
     map.crange[i] = fcontradius[item_no]/map.delx[i];
//printf("map radius = %d\n",map.crange[0]);
}

void setminden(int item_no,bonedata& bone1,griddata& map1)
{
  static int iprev = -1;

  if(iprev!=item_no){
     iprev = item_no;  
     bone1.minden = fminden[item_no];
     if(bone1.iexist!=0)
         bone1.iexist=6; // This will make setmapsub find new bones but not write new maidfile
     setmapsub(1,map1,bone1);
  } // if iprev != item_no
}

void setcontlevel(int item_no,griddata& map)
{
  map.conlevel =maidfile.denscale *fcontlevel[item_no];
printf("map.conlevel = %f\n",map.conlevel);
}

void radcont_cb0(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setcontrad(item_no,map[1]);
}
void radcont_cb1(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setcontrad(item_no,map[2]);
}
void radcont_cb2(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setcontrad(item_no,map[3]);
}
void radcont_cb3(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setcontrad(item_no,map[4]);
}
void radcont_cb4(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setcontrad(item_no,map[5]);
}
void radcont_cb5(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setcontrad(item_no,map[6]);
}

void levelcont_cb0(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setcontlevel(item_no,map[1]);
}
void levelcont_cb1(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setcontlevel(item_no,map[2]);
}
void levelcont_cb2(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setcontlevel(item_no,map[3]);
}
void levelcont_cb3(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setcontlevel(item_no,map[4]);
}
void levelcont_cb4(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setcontlevel(item_no,map[5]);
}
void levelcont_cb5(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setcontlevel(item_no,map[6]);
}


void setcolor(int item_no,griddata& map)
{
  int i;
  switch(item_no){
    case 0:
       for(i=0;i<=2;i++) 
          map.color[i]= bluev[i];
       break;
    case 1: 
       for(i=0;i<=2;i++) 
          map.color[i]= redv[i];
       break;
    case 2: 
       for(i=0;i<=2;i++) 
          map.color[i]= lightbluev[i];
       break;
    case 3: 
       for(i=0;i<=2;i++) 
          map.color[i]= yellowv[i];
       break;
    case 4: 
       for(i=0;i<=2;i++) 
          map.color[i]= pinkv[i];
       break;
    case 5: 
       for(i=0;i<=2;i++) 
          map.color[i]= cyanv[i];
       break;
    case 6: 
       for(i=0;i<=2;i++) 
          map.color[i]= magentav[i];
       break;
    case 7: 
       for(i=0;i<=2;i++) 
          map.color[i]= greenv[i];
       break;
    case 8: 
       for(i=0;i<=2;i++) 
          map.color[i]= whitev[i];
       break;
    case 9: 
       for(i=0;i<=2;i++) 
          map.color[i]= blackv[i];
       break;
  }
}

void color_cb0(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
printf("in color_cb0  item_no = %d\n",item_no);
    setcolor(item_no,map[1]);
}
void color_cb1(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setcolor(item_no,map[2]);
}
void color_cb2(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setcolor(item_no,map[3]);
}
void color_cb3(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setcolor(item_no,map[4]);
}
void color_cb4(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setcolor(item_no,map[5]);
}
void color_cb5(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setcolor(item_no,map[6]);
}

void mapsub_cb0(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setmapsub(item_no,map[1],bone[1]);
}
void mapsub_cb1(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setmapsub(item_no,map[2],bone[2]);
}
void mapsub_cb2(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setmapsub(item_no,map[3],bone[3]);
}
void mapsub_cb3(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setmapsub(item_no,map[4],bone[4]);
}
void mapsub_cb4(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setmapsub(item_no,map[5],bone[5]);
}
void mapsub_cb5(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setmapsub(item_no,map[6],bone[6]);
}
void minden_cb0(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
printf("In minden+cb0  item_no = %d\n",item_no);
    setminden(item_no,bone[1],map[1]);
}
void minden_cb1(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setminden(item_no,bone[2],map[2]);
}
void minden_cb2(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setminden(item_no,bone[3],map[3]);
}
void minden_cb3(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setminden(item_no,bone[4],map[4]);
}
void minden_cb4(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setminden(item_no,bone[5],map[5]);
}
void minden_cb5(Widget widget,XtPointer client_data,XtPointer  call_data)
{
    int item_no = (int) client_data;
    setminden(item_no,bone[6],map[6]);
}
 
void mappulldown(Widget menubar)
/* Note - use same radius[] array for contour (set for each
    map) and bone (set for all bones) - thus, must use
    same default.  Also, this default is also used for
    pdb radius, thus if change default, should change in
    pdbmenu.c++ also
*/
{
    char mapstr[NMAPS][10],ch[10];
    int colornum,contournum,levelnum,mindennum;
    XmString xmpdb[NMAPS],maponoff,radius[10],level[10],contlevel,setboneradius,setradius;
    XmString contcolor,colorv[20],boneonoff,contonoff,minden[10],boneminset;
    XmString editboneonoff,inputbonept,inputfitnum,writebonepdb;
    Widget radpullright[10],colorpullright[10],levelpullright[10],widget;
    Widget mindenpullright[10],boneradpullright;

    for(int i=1;i<NMAPS;i++){
       strcpy(mapstr[i],"MAP");
       sprintf(ch,"%d",i);
       strcat(mapstr[i],ch);
       strcat(mapstr[i],"...");
       xmpdb[i] = XmStringCreateLocalized (mapstr[i]);
    }
   contonoff = XmStringCreateLocalized ("ALL CONTOURS ON/OFF ");
   boneminset = XmStringCreateLocalized ("SET MIN DENSITY FOR BONES (STD.DEV)");
   maponoff = XmStringCreateLocalized ("CONTOUR ON/OFF ");
   boneonoff = XmStringCreateLocalized ("BONE ON/OFF");
   setradius = XmStringCreateLocalized("CONTOUR RADIUS (Ang)");
   setboneradius = XmStringCreateLocalized("BONE RADIUS (Ang)");
   contcolor =  XmStringCreateLocalized("COLOR");
   contlevel =  XmStringCreateLocalized("CONTOUR LEVEL (std)");
   editboneonoff =  XmStringCreateLocalized("EDITED BONES ON/OFF");
   inputbonept=  XmStringCreateLocalized("INPUT BONE PT ON/OFF");
   inputfitnum=  XmStringCreateLocalized("EDIT BONE AT CTERM END OF INPUT FIT - 0 FOR ALL");
   writebonepdb=  XmStringCreateLocalized("WRITE BONES IN SPHERE TO PDB"); 
   radius[0] = XmStringCreateLocalized ("5");
   radius[1] = XmStringCreateLocalized ("7.5 (Default)");
   radius[2] = XmStringCreateLocalized ("10 ");
   radius[3] = XmStringCreateLocalized ("12.5");
   radius[4] = XmStringCreateLocalized ("15");
   radius[5] = XmStringCreateLocalized ("17.5");
   radius[6] = XmStringCreateLocalized ("20.0");
   minden[0] = XmStringCreateLocalized ("0.8");
   minden[1] = XmStringCreateLocalized ("1.0");
   minden[2] = XmStringCreateLocalized ("1.2");
   minden[3] = XmStringCreateLocalized ("1.4 (Default)");
   minden[4] = XmStringCreateLocalized ("1.6");
   minden[5] = XmStringCreateLocalized ("1.8");
   minden[6] = XmStringCreateLocalized ("2.0");
   colorv[0]=  XmStringCreateLocalized("Blue");
   colorv[1]=  XmStringCreateLocalized("Red");
   colorv[2]=  XmStringCreateLocalized("Lightblue");
   colorv[3]=  XmStringCreateLocalized("Yellow");
   colorv[4]=  XmStringCreateLocalized("Pink");
   colorv[5]=  XmStringCreateLocalized("Cyan");
   colorv[6]=  XmStringCreateLocalized("Magenta");
   colorv[7]=  XmStringCreateLocalized("Green");
   colorv[8]=  XmStringCreateLocalized("White");
   colorv[9]=  XmStringCreateLocalized("Black");
   level[0] = XmStringCreateLocalized ("0.5");
   level[1] = XmStringCreateLocalized ("1.0 ");
   level[2] = XmStringCreateLocalized ("1.5 (Default)");
   level[3] = XmStringCreateLocalized ("2.0");
   level[4] = XmStringCreateLocalized ("2.5");
   level[5] = XmStringCreateLocalized ("3.0");
   level[6] = XmStringCreateLocalized ("3.5");
   level[7] = XmStringCreateLocalized ("4.0");
   level[8] = XmStringCreateLocalized ("5.0");
   level[9] = XmStringCreateLocalized ("6.0");
   
    mapmenu=XmVaCreateSimplePulldownMenu (menubar, "map_menu", 2, map_cb,
        XmVaCASCADEBUTTON, xmpdb[1],'W',
        XmVaCASCADEBUTTON, xmpdb[2],'W',
        XmVaCASCADEBUTTON, xmpdb[3],'W',
        XmVaCASCADEBUTTON, xmpdb[4],'W',
        XmVaCASCADEBUTTON, xmpdb[5],'W',
        XmVaCASCADEBUTTON, xmpdb[6],'W',
        XmVaCHECKBUTTON,contonoff,NULL, NULL, NULL,  // button_6
        XmVaCASCADEBUTTON,setboneradius,NULL,
        XmVaCHECKBUTTON,editboneonoff,NULL, NULL, NULL,  // button_8
        XmVaCHECKBUTTON,inputbonept,NULL, NULL, NULL,  // button_9
        XmVaPUSHBUTTON,inputfitnum,NULL, NULL, NULL,  // button_10
        XmVaPUSHBUTTON,writebonepdb,NULL, NULL, NULL,  // button_11
        NULL);

  contournum = 2;  // menu position 
  colornum = 3;
  levelnum = 4;
  mindennum=5;
  boneradpullright=XmVaCreateSimplePulldownMenu (mapmenu,
            "bpullright", 7 ,bonerad_cb,
             XmVaRADIOBUTTON,radius[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[6],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);   
  sc.mappullright[1] = XmVaCreateSimplePulldownMenu (mapmenu,
            "pullright", 0 ,mapsub_cb0,XmVaCHECKBUTTON, maponoff,NULL, NULL, NULL,
             XmVaCHECKBUTTON, boneonoff,NULL, NULL, NULL,
             XmVaCASCADEBUTTON,setradius,NULL,
             XmVaCASCADEBUTTON,contcolor,NULL,
             XmVaCASCADEBUTTON,contlevel,NULL,
             XmVaCASCADEBUTTON,boneminset,NULL,
             NULL);
   sc.mappullright[2] = XmVaCreateSimplePulldownMenu (mapmenu,
            "pullright", 1 ,mapsub_cb1,XmVaCHECKBUTTON, maponoff,NULL, NULL, NULL,
             XmVaCHECKBUTTON, boneonoff,NULL, NULL, NULL,
             XmVaCASCADEBUTTON,setradius,NULL,
             XmVaCASCADEBUTTON,contcolor,NULL,
             XmVaCASCADEBUTTON,contlevel,NULL,
             XmVaCASCADEBUTTON,boneminset,NULL,
             NULL);
   sc.mappullright[3] = XmVaCreateSimplePulldownMenu (mapmenu,
            "pullright", 2 ,mapsub_cb2,XmVaCHECKBUTTON, maponoff,NULL, NULL, NULL,
             XmVaCHECKBUTTON, boneonoff,NULL, NULL, NULL,
             XmVaCASCADEBUTTON,setradius,NULL,
             XmVaCASCADEBUTTON,contcolor,NULL,
             XmVaCASCADEBUTTON,contlevel,NULL,
             XmVaCASCADEBUTTON,boneminset,NULL,
             NULL);
   sc.mappullright[4] = XmVaCreateSimplePulldownMenu (mapmenu,
            "pullright", 3 ,mapsub_cb3,XmVaCHECKBUTTON, maponoff,NULL, NULL, NULL,
             XmVaCHECKBUTTON, boneonoff,NULL, NULL, NULL,
             XmVaCASCADEBUTTON,setradius,NULL,
             XmVaCASCADEBUTTON,contcolor,NULL,
             XmVaCASCADEBUTTON,contlevel,NULL,
             XmVaCASCADEBUTTON,boneminset,NULL,
             NULL);
   sc.mappullright[5] = XmVaCreateSimplePulldownMenu (mapmenu,
            "pullright", 4 ,mapsub_cb4,XmVaCHECKBUTTON, maponoff,NULL, NULL, NULL,
             XmVaCHECKBUTTON, boneonoff,NULL, NULL, NULL,
             XmVaCASCADEBUTTON,setradius,NULL,
             XmVaCASCADEBUTTON,contcolor,NULL,
             XmVaCASCADEBUTTON,contlevel,NULL,
             XmVaCASCADEBUTTON,boneminset,NULL,
             NULL);
   sc.mappullright[6] = XmVaCreateSimplePulldownMenu (mapmenu,
            "pullright", 5 ,mapsub_cb5,XmVaCHECKBUTTON, maponoff,NULL, NULL, NULL,
             XmVaCHECKBUTTON, boneonoff,NULL, NULL, NULL,
             XmVaCASCADEBUTTON,setradius,NULL,
             XmVaCASCADEBUTTON,contcolor,NULL,
             XmVaCASCADEBUTTON,contlevel,NULL,
             XmVaCASCADEBUTTON,boneminset,NULL,
             NULL);
   for(i=1;i<NMAPS;i++) // Turn off sensitivitivity  - look pale
       XtSetSensitive(sc.mappullright[i],0);

   colorpullright[1]=XmVaCreateSimplePulldownMenu (sc.mappullright[1],
            "rpullright", colornum ,color_cb0,
             XmVaRADIOBUTTON,colorv[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[6],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[7],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[8],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[9],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);   
   colorpullright[2]=XmVaCreateSimplePulldownMenu (sc.mappullright[2],
            "rpullright", colornum ,color_cb1,
             XmVaRADIOBUTTON,colorv[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[6],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[7],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[8],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[9],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);   
   colorpullright[3]=XmVaCreateSimplePulldownMenu (sc.mappullright[3],
            "rpullright", colornum ,color_cb2,
             XmVaRADIOBUTTON,colorv[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[6],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[7],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[8],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[9],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);   
   colorpullright[4]=XmVaCreateSimplePulldownMenu (sc.mappullright[4],
            "rpullright", colornum ,color_cb3,
             XmVaRADIOBUTTON,colorv[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[6],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[7],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[8],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[9],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);   
   colorpullright[5]=XmVaCreateSimplePulldownMenu (sc.mappullright[5],
            "rpullright", colornum ,color_cb4,
             XmVaRADIOBUTTON,colorv[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[6],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[7],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[8],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[9],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);   
   colorpullright[6]=XmVaCreateSimplePulldownMenu (sc.mappullright[6],
            "rpullright", colornum ,color_cb5,
             XmVaRADIOBUTTON,colorv[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[6],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[7],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[8],NULL, NULL, NULL,
             XmVaRADIOBUTTON,colorv[9],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);   
   radpullright[1]=XmVaCreateSimplePulldownMenu (sc.mappullright[1],
            "rpullright", contournum ,radcont_cb0,
             XmVaRADIOBUTTON,radius[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[6],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);   
   radpullright[2]=XmVaCreateSimplePulldownMenu (sc.mappullright[2],
            "rpullright", contournum ,radcont_cb1,
             XmVaRADIOBUTTON,radius[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[6],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);   
   radpullright[3]=XmVaCreateSimplePulldownMenu (sc.mappullright[3],
            "rpullright", contournum ,radcont_cb2,
             XmVaRADIOBUTTON,radius[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[6],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);   
   radpullright[4]=XmVaCreateSimplePulldownMenu (sc.mappullright[4],
            "rpullright", contournum ,radcont_cb3,
             XmVaRADIOBUTTON,radius[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[6],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);   
   radpullright[5]=XmVaCreateSimplePulldownMenu (sc.mappullright[5],
            "rpullright", contournum ,radcont_cb4,
             XmVaRADIOBUTTON,radius[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[6],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);   
   radpullright[6]=XmVaCreateSimplePulldownMenu (sc.mappullright[6],
            "rpullright", contournum ,radcont_cb5,
             XmVaRADIOBUTTON,radius[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,radius[6],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);
   levelpullright[1]=XmVaCreateSimplePulldownMenu (sc.mappullright[1],
            "lpullright", levelnum ,levelcont_cb0,
             XmVaRADIOBUTTON,level[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[6],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[7],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[8],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[9],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);   
   levelpullright[2]=XmVaCreateSimplePulldownMenu (sc.mappullright[2],
            "lpullright", levelnum ,levelcont_cb1,
             XmVaRADIOBUTTON,level[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[6],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[7],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[8],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[9],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);   
   levelpullright[3]=XmVaCreateSimplePulldownMenu (sc.mappullright[3],
            "lpullright", levelnum ,levelcont_cb2,
             XmVaRADIOBUTTON,level[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[6],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[7],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[8],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[9],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);   
   levelpullright[4]=XmVaCreateSimplePulldownMenu (sc.mappullright[4],
            "lpullright", levelnum ,levelcont_cb3,
             XmVaRADIOBUTTON,level[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[6],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[7],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[8],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[9],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);   
   levelpullright[5]=XmVaCreateSimplePulldownMenu (sc.mappullright[5],
            "lpullright", levelnum ,levelcont_cb4,
             XmVaRADIOBUTTON,level[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[6],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[7],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[8],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[9],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);   
   levelpullright[6]=XmVaCreateSimplePulldownMenu (sc.mappullright[6],
            "lpullright", levelnum ,levelcont_cb5,
             XmVaRADIOBUTTON,level[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[6],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[7],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[8],NULL, NULL, NULL,
             XmVaRADIOBUTTON,level[9],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);
  mindenpullright[1]=XmVaCreateSimplePulldownMenu (sc.mappullright[1],
            "mpullright", mindennum ,minden_cb0,
             XmVaRADIOBUTTON,minden[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,minden[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,minden[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,minden[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,minden[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,minden[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,minden[6],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);   
   mindenpullright[2]=XmVaCreateSimplePulldownMenu (sc.mappullright[2],
            "mpullright", mindennum ,minden_cb1,
             XmVaRADIOBUTTON,minden[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,minden[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,minden[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,minden[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,minden[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,minden[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,minden[6],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);   
   mindenpullright[3]=XmVaCreateSimplePulldownMenu (sc.mappullright[3],
            "mpullright", mindennum ,minden_cb2,
             XmVaRADIOBUTTON,minden[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,minden[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,minden[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,minden[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,minden[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,minden[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,minden[6],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);   
   mindenpullright[4]=XmVaCreateSimplePulldownMenu (sc.mappullright[4],
            "mpullright", mindennum ,minden_cb3,
             XmVaRADIOBUTTON,minden[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,minden[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,minden[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,minden[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,minden[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,minden[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,minden[6],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);   
   mindenpullright[5]=XmVaCreateSimplePulldownMenu (sc.mappullright[5],
            "mpullright", mindennum ,minden_cb4,
             XmVaRADIOBUTTON,minden[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,minden[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,minden[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,minden[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,minden[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,minden[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,minden[6],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);   
   mindenpullright[6]=XmVaCreateSimplePulldownMenu (sc.mappullright[6],
            "mpullright", mindennum ,minden_cb5,
             XmVaRADIOBUTTON,minden[0],NULL, NULL, NULL,
             XmVaRADIOBUTTON,minden[1],NULL, NULL, NULL,
             XmVaRADIOBUTTON,minden[2],NULL, NULL, NULL,
             XmVaRADIOBUTTON,minden[3],NULL, NULL, NULL,
             XmVaRADIOBUTTON,minden[4],NULL, NULL, NULL,
             XmVaRADIOBUTTON,minden[5],NULL, NULL, NULL,
             XmVaRADIOBUTTON,minden[6],NULL, NULL, NULL,
             XmNradioBehavior, True,     /* RowColumn resources to enforce */
             XmNradioAlwaysOne, True,    /* radio behavior in Menu */
             NULL);
#if 0 // CAN NOT set default value menu pull down - otherwise call back runs twice 
          // once with default and then with new value
          // I do not know where to put it
    for(i=1;i<=6;i++){ // set default values      
        if (widget = XtNameToWidget (radpullright[i], "button_2")) 
                XtVaSetValues (widget, XmNset,True, NULL);             
        if (widget = XtNameToWidget (colorpullright[i], "button_0")) 
                XtVaSetValues (widget, XmNset,True, NULL);
        if (widget = XtNameToWidget (levelpullright[i], "button_1")) 
                XtVaSetValues (widget, XmNset,True, NULL);
        if (widget = XtNameToWidget (mindenpullright[i], "button_3")) 
               XtVaSetValues (widget, XmNset,True, NULL);
    } 
#endif            
 
  if (widget = XtNameToWidget (boneradpullright, "button_2"))
                XtVaSetValues (widget, XmNset,True, NULL); // Default bone radius            
  if (widget = XtNameToWidget (mapmenu,"button_6")) //DEFAULT:  Turn on check box for label on/off button
            XtVaSetValues (widget, XmNset, True, NULL);
  if (widget = XtNameToWidget (mapmenu,"button_8")) //DEFAULT:  Turn off check box for edit bones on/off button
            XtVaSetValues (widget, XmNset,False, NULL);
  if (widget = XtNameToWidget (mapmenu,"button_9")) //DEFAULT:  Turn off check box for highlight bone point on/off button
            XtVaSetValues (widget, XmNset,False, NULL);
    for(i=0;i<=6;i++){
       XmStringFree (radius[i]);
       XmStringFree (minden[i]);
    }
    for(i=0;i<=9;i++){
       XmStringFree (colorv[i]);
       XmStringFree (level[i]);
    }
    XmStringFree(setradius); 
    XmStringFree(setboneradius); 
    XmStringFree(maponoff);
    XmStringFree(contcolor);
    XmStringFree(boneonoff);
    XmStringFree(contlevel);
    XmStringFree(contonoff);
    XmStringFree(boneminset);
    XmStringFree(editboneonoff);
    XmStringFree(inputbonept);
    XmStringFree(inputfitnum);
    for(i=1;i<NMAPS;i++)
       XmStringFree (xmpdb[i]);
 }   
    
