Skip to content

Commit 729b970

Browse files
authored
Merge branch 'main' into bug_fixing_chiwin_crash
2 parents 29acb3b + c3c61a1 commit 729b970

File tree

3 files changed

+64
-78
lines changed

3 files changed

+64
-78
lines changed

src/ProjectSave.f90

Lines changed: 41 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -245,10 +245,10 @@ LOGICAL FUNCTION PrjReadWriteImpl(ThePrjFile, ReadOrWrite, ForceOldVersion)
245245
COMMON /BATEXE/ in_batch
246246

247247
INTEGER, EXTERNAL :: GetCrystalSystem
248-
INTEGER I, j, RW
249-
CHARACTER*(255) tString
250-
CHARACTER*(10) Version ! We have patch releases like "DASH 2.1.1"
251-
REAL VerFig, PatchLevel
248+
INTEGER I, j, RW, MAJOR_IDX, MINOR_IDX, PATCH_IDX, END_IDX
249+
INTEGER MajorVersion,MinorVersion,PatchVersion
250+
CHARACTER*(255) tString, csol
251+
REAL PatchLevel
252252
REAL, PARAMETER :: TOLER = 1E-6
253253

254254
INTEGER BFIOErrorCode
@@ -268,21 +268,44 @@ LOGICAL FUNCTION PrjReadWriteImpl(ThePrjFile, ReadOrWrite, ForceOldVersion)
268268
OPEN(UNIT=hPrjFile,FILE=ThePrjFile,ACCESS='DIRECT',RECL=cRECLMult,FORM='UNFORMATTED',ERR=999)
269269
iPrjRecNr = 1
270270
! Read / Write the header
271-
tString = ProgramVersion//' project file'
271+
tString = TRIM(ProgramVersion)//' project file'
272272
CALL FileRWString(hPrjFile, iPrjRecNr, RW, tString)
273+
274+
MAJOR_IDX = 6
275+
END_IDX = LEN(TRIM(tString))
276+
PATCH_IDX = LEN(TRIM(tString))
277+
DO I = MAJOR_IDX,LEN(TRIM(tString))
278+
IF ( tString(I:I) .EQ. '.' ) THEN
279+
MINOR_IDX = I
280+
EXIT
281+
ENDIF
282+
ENDDO
283+
284+
DO I = MINOR_IDX+1,LEN(TRIM(tString))
285+
IF ( tString(I:I) .EQ. '.' ) THEN
286+
PATCH_IDX = I
287+
EXIT
288+
ENDIF
289+
ENDDO
290+
291+
DO I = PATCH_IDX+1,LEN(TRIM(tString))
292+
IF ( tString(I:I) .EQ. ' ' ) THEN
293+
END_IDX = I
294+
EXIT
295+
ENDIF
296+
ENDDO
297+
298+
READ (tString(MAJOR_IDX:MINOR_IDX-1),'(I)', ERR=999) MajorVersion
299+
READ (tString(MINOR_IDX+1:PATCH_IDX-1),'(I)', ERR=999) MinorVersion
300+
IF ( PATCH_IDX .NE. LEN(TRIM(tString)) ) THEN
301+
READ (tString(PATCH_IDX+1:END_IDX-1),'(I)', ERR=999) PatchVersion
302+
ELSE
303+
PatchVersion = 0
304+
ENDIF
305+
273306
IF ( BFIOErrorCode .EQ. 1 ) GOTO 999
274307
! If read, store program version for later reference
275-
IF (RW .EQ. cRead) THEN
276-
! Convert version string to real, include patch level
277-
READ (tString(6:8),*, ERR=999) VerFig
278-
IF ( tString(9:9) .EQ. " " ) THEN
279-
Version = tString(1:8)
280-
ELSE
281-
Version = tString(1:10)
282-
READ (tString(10:10),*) PatchLevel
283-
VerFig = VerFig + PatchLevel / 100.0
284-
ENDIF
285-
ENDIF
308+
286309
! Read / Write radiation source
287310
CALL FileRWInteger(hPrjFile, iPrjRecNr, RW, JRadOption)
288311
! Read / Write Wavelength
@@ -392,7 +415,7 @@ LOGICAL FUNCTION PrjReadWriteImpl(ThePrjFile, ReadOrWrite, ForceOldVersion)
392415
! Must read/write hydrogen treatment first, because that is necessary to
393416
! calculate the atomic weightings. This wasn't written out in version 3.0, so need
394417
! to add a check.
395-
IF ( (RW .EQ. cWrite) .OR. (Version(6:8) .NE. "3.0") ) THEN
418+
IF ( (RW .EQ. cWrite) .OR. (MajorVersion .LE. 3 ) .OR. (MajorVersion .EQ. 3 .AND. MinorVersion .EQ. 0) ) THEN
396419
IF ( .NOT. ForceOldVersion ) THEN
397420
CALL FileRWInteger(hPrjFile, iPrjRecNr, RW, HydrogenTreatment)
398421
IF ( BFIOErrorCode .EQ. 1 ) GOTO 999
@@ -417,7 +440,7 @@ LOGICAL FUNCTION PrjReadWriteImpl(ThePrjFile, ReadOrWrite, ForceOldVersion)
417440
CALL SA_Parameter_Set
418441
ENDIF
419442
! Read / Write MDB and SA Distance restraints. Version 3.2 onward
420-
IF ( (RW .EQ. cWrite) .OR. (VerFig .GT. 3.2 - TOLER) ) THEN
443+
IF ( (RW .EQ. cWrite) .OR. (MajorVersion .GT. 3) .OR. (MajorVersion .EQ. 3 .AND. MinorVersion .GE. 2) ) THEN
421444
CALL PrjReadWriteParameterBoundsIncludeMDB
422445
IF ( BFIOErrorCode .EQ. 1 ) GOTO 999
423446
CALL PrjErrTrace

src/SA_refresh.f90

Lines changed: 22 additions & 59 deletions
Original file line numberDiff line numberDiff line change
@@ -115,78 +115,41 @@ SUBROUTINE ViewStructure(TheFileName, BuiltInOnly)
115115
INTEGER, DIMENSION(2) :: ID
116116

117117

118-
IF (BuiltInOnly) THEN
119-
tBuiltInMercury = .TRUE.
120-
tUseClient = .TRUE.
121-
ELSE
118+
122119
! Get the argument for the viewer from the Configuration Window
123-
CALL PushActiveWindowID
124-
CALL SelectDASHDialog(IDD_Configuration)
125-
tBuiltInMercury = DASHWDialogGetCheckBoxLogical(IDF_BuiltIn_Mercury)
126-
tUseClient = DASHWDialogGetCheckBoxLogical(IDF_Use_Client)
127-
CALL DASHWDialogGetString(IDF_ViewExe, ViewerExecutable)
128-
CALL DASHWDialogGetString(IDF_ViewArg, ViewArg)
129-
CALL PopActiveWindowID
130-
ENDIF
131-
132-
133-
IF (tBuiltInMercury) THEN
134-
if (LEN_TRIM(MercuryExecutable) .EQ. 0) THEN
135-
CALL ErrorMessage("Could not find default mercury location.")
136-
RETURN
137-
ENDIF
138-
139-
CALL IOsFullPathname(TheFileName,FullFileName)
140-
M = WInfoError(3) ! Clear errors
141-
IF (tUseClient) THEN
142-
CALL IOSCommand( TRIM(MercuryExecutable)//' -load-all-files -client "'//TRIM(FullFileName)//'"', ProcSilent, IDPROC=ID)
143-
ELSE
144-
CALL IOSCommand( TRIM(MercuryExecutable)//' -load-all-files "'//TRIM(FullFileName)//'"', ProcSilent, IDPROC=ID)
145-
ENDIF
146-
DO
147-
CALL IOsCommandCheck(ID, ISTATUS, IEXCOD)
148-
IF (ISTATUS==0) EXIT
149-
CALL IOsWait(5)
150-
END DO
151-
152-
IF ( ISTATUS.EQ.0 ) &
153-
RETURN
154-
155-
IF ( ISTATUS.EQ.2 ) THEN
156-
tArgStr = 'The file named '//TRIM(FullFileName)//' Doesnt seem to exist or is unreadable ...'
157-
CALL ErrorMessage(TRIM(tArgStr))
158-
RETURN
159-
ENDIF
160-
ELSE
161-
tExeStr = ViewerExecutable
162-
tArgStr = ViewArg
163-
164-
I = LEN_TRIM(tExeStr)
120+
CALL PushActiveWindowID
121+
CALL SelectDASHDialog(IDD_Configuration)
122+
123+
tUseClient = DASHWDialogGetCheckBoxLogical(IDF_Use_Client)
124+
CALL DASHWDialogGetString(IDF_ViewExe, ViewerExecutable)
125+
CALL DASHWDialogGetString(IDF_ViewArg, ViewArg)
126+
CALL PopActiveWindowID
127+
tExeStr = ViewerExecutable
128+
tArgStr = ViewArg
129+
130+
I = LEN_TRIM(tExeStr)
165131

166-
IF (I .EQ. 0) THEN
132+
IF (I .EQ. 0) THEN
167133
CALL ErrorMessage('DASH could not launch the viewer. '// &
168134
'No viewer executable is currently specified.'//CHAR(13)//&
169135
'This can be changed in the Configuration... window'//CHAR(13)//&
170136
'under Options in the menu bar.')
171137
RETURN
172-
ENDIF
138+
ENDIF
173139

174-
INQUIRE(FILE = tExeStr(1:I),EXIST=exists)
175-
IF (.NOT. exists) GOTO 999
176-
M = InfoError(1) ! Clear errors
177-
CALL IOSCommand('"'//tExeStr(1:I)//'" '//TRIM(tArgStr)//' "'//TRIM(TheFileName)//'"')
178-
IF (InfoError(1) .NE. 0) GOTO 999
179-
RETURN
180-
ENDIF
181-
999 IF (tBuiltInMercury) THEN
182-
tArgStr = 'DASH could not find or launch the built in Mercury: '//CHAR(13)//tExeStr(1:I)
183-
ELSE
140+
INQUIRE(FILE = tExeStr(1:I),EXIST=exists)
141+
IF (.NOT. exists) GOTO 999
142+
M = InfoError(1) ! Clear errors
143+
CALL IOSCommand('"'//tExeStr(1:I)//'" '//TRIM(tArgStr)//' "'//TRIM(TheFileName)//'"')
144+
IF (InfoError(1) .NE. 0) GOTO 999
145+
RETURN
146+
999 CONTINUE
147+
184148
tArgStr = 'DASH could not find or launch the viewer. '// &
185149
'The viewer executable is currently configured'//CHAR(13)//&
186150
'to launch the program '//tExeStr(1:I)//CHAR(13)//&
187151
'This can be changed in the Configuration... window'//CHAR(13)//&
188152
'under Options in the menu bar.'
189-
ENDIF
190153
CALL ErrorMessage(TRIM(tArgStr))
191154
RETURN
192155

src/variables.f90.in

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,7 @@
9292
! Stops the user constantly being reminded that there isn't a path
9393
! to a Mogul exe specified
9494

95-
CHARACTER(10) :: ProgramVersion
95+
CHARACTER(15) :: ProgramVersion
9696
DATA ProgramVersion / 'DASH @DASH_VERSION@' /
9797

9898
! File information; Names of files used by DASH For I/O

0 commit comments

Comments
 (0)