Make sure figure legends are adapted to xmgr/xmgrace
authorErik Lindahl <erik@kth.se>
Thu, 12 Jun 2014 12:39:24 +0000 (14:39 +0200)
committerGerrit Code Review <gerrit@gerrit.gromacs.org>
Sat, 14 Jun 2014 04:29:58 +0000 (06:29 +0200)
A few programs were not using the xvgr_legend call. g_mdmat
has been modified to use it, and for g_analyse and g_enemat
I at least fixed the existing direct-writing code by adding
a conditional.

Fixes #783.

Change-Id: I782af539b93737b570f266ba744e718fbd846e5f

src/tools/gmx_analyze.c
src/tools/gmx_enemat.c
src/tools/gmx_mdmat.c

index 2b8f2827b3bf3c95c2e14fefe43874bdc2319a7f..b201f94be8b7795e25835eb06ed0aefcddb0f119 100644 (file)
@@ -615,11 +615,16 @@ static void estimate_error(const char *eefile, int nb_min, int resol, int n,
         }
         fprintf(stdout, "Set %3d:  err.est. %g  a %g  tau1 %g  tau2 %g\n",
                 s+1, ee, a, tau1, tau2);
-        if(output_env_get_print_xvgr_codes(oenv))
+        if (output_env_get_xvg_format(oenv) == exvgXMGR)
         {
             fprintf(fp, "@ legend string %d \"av %f\"\n", 2*s, av[s]);
             fprintf(fp, "@ legend string %d \"ee %6g\"\n",2*s+1, sig[s]*anal_ee_inf(fitparm, n*dt));
         }
+        else if (output_env_get_xvg_format(oenv) == exvgXMGRACE)
+        {
+            fprintf(fp, "@ s%d legend \"av %f\"\n", 2*s, av[s]);
+            fprintf(fp, "@ s%d legend \"ee %6g\"\n",2*s+1, sig[s]*anal_ee_inf(fitparm, n*dt));
+        }
         for (i = 0; i < nbs; i++)
         {
             fprintf(fp, "%g %g %g\n", tbs[i], sig[s]*sqrt(ybs[i]/(n*dt)),
index f60972502b42b6edbd0c4e14d27e3b0a48b70da9..2add7ed450f34a4eeff0cab2a137f46c0e286066 100644 (file)
@@ -514,20 +514,32 @@ int gmx_enemat(int argc, char *argv[])
         j = 0;
         if (output_env_get_print_xvgr_codes(oenv))
         {
+            char str1[STRLEN],str2[STRLEN];
+            if(output_env_get_xvg_format(oenv) == exvgXMGR)
+            {
+                sprintf(str1,"@ legend string ");
+                sprintf(str2," ");
+            }
+            else
+            {
+                sprintf(str1,"@ s");
+                sprintf(str2," legend ");
+            }
+            
             for (m = 0; (m < egNR+egSP); m++)
             {
                 if (egrp_use[m])
                 {
-                    fprintf(out, "@ legend string %d \"%s\"\n", j++, egrp_nm[m]);
+                    fprintf(out, "%s%d%s \"%s\"\n", str1, j++, str2, egrp_nm[m]);
                 }
             }
             if (bFree)
             {
-                fprintf(out, "@ legend string %d \"%s\"\n", j++, "Free");
+                fprintf(out, "%s%d%s \"%s\"\n", str1, j++, str2, "Free");
             }
             if (bFree)
             {
-                fprintf(out, "@ legend string %d \"%s\"\n", j++, "Diff");
+                fprintf(out, "%s%d%s \"%s\"\n", str1, j++, str2, "Diff");
             }
             fprintf(out, "@TYPE xy\n");
             fprintf(out, "#%3s", "grp");
index a5df7ef22de39ab761c40b195c4ed449f1e2aa89..3e960a3bdb26a9687795b3f3ed7796440372f558 100644 (file)
@@ -368,23 +368,22 @@ int gmx_mdmat(int argc, char *argv[])
 
     if (bCalcN)
     {
+        char **legend;
+        
+        snew(legend,5);
+        for(i=0;i<5;i++)
+        {
+            snew(legend[i],STRLEN);
+        }
         tot_nmat(nres, natoms, nframes, totnmat, tot_n, mean_n);
         fp = xvgropen(ftp2fn(efXVG, NFILE, fnm),
                       "Increase in number of contacts", "Residue", "Ratio", oenv);
-        if(output_env_get_print_xvgr_codes(oenv))
-        {
-            fprintf(fp, "@ legend on\n");
-            fprintf(fp, "@ legend box on\n");
-            fprintf(fp, "@ legend loctype view\n");
-            fprintf(fp, "@ legend 0.75, 0.8\n");
-            fprintf(fp, "@ legend string 0 \"Total/mean\"\n");
-            fprintf(fp, "@ legend string 1 \"Total\"\n");
-            fprintf(fp, "@ legend string 2 \"Mean\"\n");
-            fprintf(fp, "@ legend string 3 \"# atoms\"\n");
-            fprintf(fp, "@ legend string 4 \"Mean/# atoms\"\n");
-            fprintf(fp, "#%3s %8s  %3s  %8s  %3s  %8s\n",
-                    "res", "ratio", "tot", "mean", "natm", "mean/atm");
-        }
+        sprintf(legend[0],"Total/mean");
+        sprintf(legend[1],"Total");
+        sprintf(legend[2],"Mean");
+        sprintf(legend[3],"# atoms");
+        sprintf(legend[4],"Mean/# atoms");
+        xvgr_legend(fp,5,(const char**)legend,oenv);
         for (i = 0; (i < nres); i++)
         {
             if (mean_n[i] == 0)