--- getcor_orig.F90	2021-01-31 16:05:08.834801880 +0000
+++ getcor.F90	2021-02-01 21:22:32.247591490 +0000
@@ -5,7 +5,7 @@
 !+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 !+ Read initial coordinates (and velocities) from restart file
 #ifdef MPI
-subroutine getcor(nr,x,v,f,ntx,box,irest,tt,temp0,writeflag,solvph,solve)
+subroutine getcor(nr,x,v,f,ntx,box,irest,tt,temp0,writeflag,solvph,solve,stagid)
 #else
 subroutine getcor(nr,x,v,f,ntx,box,irest,tt,writeflag)
 #endif
@@ -32,11 +32,12 @@
    use sander_lib, only  : check_inpcrd_overflow, get_num_tokens
 #ifdef MPI
    use remd, only : rem
+   use sgld, only : isgld
 #endif
 
    implicit none
 #  include "ew_cntrl.h"
-   integer lun,nr,ntx,irest
+   integer lun,nr,ntx,irest,stagid
    _REAL_ x(*),v(*),f(*),box(3),tt
 #ifdef MPI
    _REAL_ temp0,solvph,solve
@@ -108,10 +109,19 @@
       ! in REM, overwrite temp0, solvph and/or solve if it's present in inpcrd/restrt
       ! DAN ROE: May want to just use temps in input file, so only 
       !          do this if a restart is requested.
-      if(rem == 1 .and. lremd_values(1) /= NO_INPUT_VALUE_FLOAT .and. irest==1) then
-         write(6, '(a)') '| Overwriting temp0 from mdin with temp0 from &
-                          &netcdf inpcrd file'
-         temp0 = lremd_values(1)
+      if(rem == 1 .and. irest==1) then
+        if (isgld > 0) then
+          if (lremd_values(1) /= NO_INPUT_VALUE_FLOAT) then
+            write(6, '(a)') '| Correcting stagid using value from inpcrd file'
+            stagid = lremd_values(1)
+          else
+            stagid = 0
+          end if
+        else if (lremd_values(1) /= NO_INPUT_VALUE_FLOAT) then
+          write(6, '(a)') '| Overwriting temp0 from mdin with temp0 from &
+            &netcdf inpcrd file'
+          temp0 = lremd_values(1)
+        end if
       else if(rem == 4 .and. lremd_values(1) /= NO_INPUT_VALUE_FLOAT .and. irest==1) then
          write(6, '(a)') '| Overwriting solvph from mdin with solvph from &
                           &netcdf inpcrd file'
@@ -123,10 +133,17 @@
       ! Multi-D REMD
       else if(rem == -1 .and. irest==1 .and. isRstValid) then
          do i = 1, remd_values_dim
-           if (lremd_types(i) == 1 .and. lremd_values(i) /= NO_INPUT_VALUE_FLOAT) then
-             write(6, '(a)') '| Overwriting temp0 from mdin with temp0 from &
-                              &netcdf inpcrd file'
-             temp0 = lremd_values(i)
+           if(isgld > 0) then
+             if (lremd_types(i) == 1 .and. lremd_values(i) /= NO_INPUT_VALUE_FLOAT) then
+               write(6, '(a)') '| Correcting stagid using value from inpcrd file'
+               stagid = lremd_values(1)
+             else
+               stagid = 0
+             end if
+           else if (lremd_types(i) == 1 .and. lremd_values(i) /= NO_INPUT_VALUE_FLOAT) then
+               write(6, '(a)') '| Overwriting temp0 from mdin with temp0 from &
+                                &netcdf inpcrd file'
+               temp0 = lremd_values(i)
            else if (lremd_types(i) == 4 .and. lremd_values(i) /= NO_INPUT_VALUE_FLOAT) then
              write(6, '(a)') '| Overwriting solvph from mdin with solvph from &
                               &netcdf inpcrd file'
@@ -171,19 +188,27 @@
       ! REMD simulations to set solvph to zero.
       call get_num_tokens(line_test, nwords)
       
-      9010 format(i5,2e15.7)
-      9011 format(i6,2e15.7)
-      9012 format(i7,2e15.7)
-      9013 format(i8,2e15.7)
-
+      9010 format(i5,2e15.7,2e15.7)
+      9011 format(i6,2e15.7,2e15.7)
+      9012 format(i7,2e15.7,2e15.7)
+      9013 format(i8,2e15.7,2e15.7)
 #ifdef MPI
       ! in REM, overwrite temp0 if it's present in inpcrd/restrt
       ! DAN ROE: May want to just use temps in input file, so only 
       !          do this if a restart is requested.
-      if(rem == 1 .and. lremd_values(1) > 0 .and. irest==1) then
-         write(6, '(a)') '| Overwriting temp0 from mdin with temp0 from &
+      if(rem == 1 .and. irest==1) then
+        if(isgld > 0) then
+          if (lremd_values(1) > 0) then
+            write(6, '(a)') '| Correcting stagid using value from inpcrd file'
+            stagid = lremd_values(1)
+          else
+            stagid = 0
+          end if
+        else if (lremd_values(1) > 0) then
+          write(6, '(a)') '| Overwriting temp0 from mdin with temp0 from &
                           &netcdf inpcrd file'
-         temp0 = lremd_values(1)
+          temp0 = lremd_values(1)
+        end if
       else if(rem == 4 .and. nwords == 3 .and. irest==1) then
          write(6, '(a)') '| Overwriting solvph from mdin with solvph from &
                           &netcdf inpcrd file'

