;+ ; NAME: ; Medit ; PURPOSE: ; Edit Mathematica program fragment created by StPlotFix.PRO to ; correct syntax errors. Optionally, tack on the rest of the ; Mathematica code needed to create a full program. ; CATEGORY: ; ; CALLING SEQUENCE: ; Medit, file, test=test, append=append ; INPUTS: ; file: Fully-qualified path name of the Mathematica program ; fragment file created by StPlotFix.PRO. ; OPTIONAL INPUTS: ; None. ; KEYWORD PARAMETERS: ; /test: Write the new file to file 'Medit.m' to allow comparison ; with the original file. ; /append: Append the rest of the Mathematica code necessary to ; have a full Mathematica program. Ths option is used when ; the procedure is invoked by StPlotFix. ; OUTPUTS: ; None. ; OPTIONAL OUTPUTS: ; None. ; COMMON BLOCKS: ; None. ; SIDE EFFECTS: ; The specified file is opened and read. After being edited ; internally a new file of the same name is written over the ; original file, unless the /test keyword is set. ; RESTRICTIONS: ; The named file must exist and have the expected structure. ; PROCEDURE: ; The file is read as a byte string. The erroneous byte patterns ; are located using StrPos, and the correct byte patterns are ; inserted. Optionally, the remaining Mathematica code from ; 'starfit.m' is read and appended to the byte array before it is ; written out. ; EXAMPLE: ; Medit,'c:\data\starpos\g0601060.m',/test ; SEE ALSO: ; StarID.PRO, StPlotFix.PRO ; MODIFICATION HISTORY: ; Written by: DPSteele, Jan. 30/97. ;- PRO Medit, file, test=test, append=append @isitdos IF Keyword_Set(test) THEN Stop ; Read in the file. OpenR, lun, file, /Get_LUN fs=FStat(lun) nb=Fs.SIZE bytes=BytArr(nb) ReadU,lun,bytes Free_LUN,lun ; Define the erroneous and correct byte patterns. patt1=[123B, 13B, 10B, 123B] len1=4 patt2=[125B, 44B, 13B, 10B, 125B] len2=5 rpatt1=[123B, 32B, 123B] rpatt2=[125B, 32B, 125B] ; Locate and replace the offending bytes. pos1=StrPos(String(bytes),String(patt1)) IF pos1 LT 0 THEN BEGIN Message,'patt1 not found; aborting',/INFORMATIONAL Return ENDIF ELSE bytes=[bytes(0:pos1-1),rpatt1,bytes(pos1+len1:*)] pos2=StrPos(String(bytes),String(patt2)) IF pos2 LT 0 THEN BEGIN Message,'patt2 not found; aborting',/INFORMATIONAL Return ENDIF ELSE bytes=[bytes(0:pos2-1),rpatt2,bytes(pos2+len2:*)] ; Load and append the rest of the Mathematica code from 'starfit.m' IF Keyword_Set(append) THEN BEGIN mfile=starroot+dd+'starfit.m' mfile=rFindFile(mfile,count=nmf) IF nmf EQ 0 THEN BEGIN Message,mfile(0)+' not found',/INFORMATIONAL Return ENDIF ELSE mfile=mfile(0) OpenR,mlun,mfile,/Get_LUN mfs=FStat(mlun) mnb=mfs.SIZE mbytes=BytArr(mnb) ReadU,mlun,mbytes Free_LUN,mlun bytes=[bytes,mbytes] ENDIF ; Write out the corrected file. IF Keyword_Set(test) THEN file=starroot+dd+'Medit.m' OpenW,lun,file,/Get_LUN WriteU,lun,bytes Free_LUN,lun Return END