FUNCTION DirExist, directory ; This function is written to tell if a directory exists or not. ; It returns 0 if the directory does NOT exist, 1 otherwise. ; Save the current directory. CD, Current=currentDirectory ; Use the Catch error handler to catch the case where we ; try to CD to a directory that doesn't exist. Catch, error IF (error NE 0) THEN BEGIN ; Directory must not exist. Return 0. RETURN, 0 ENDIF ; Try to CD to the directory. If it doesn't exist, an error occurs. CD, directory ; Well, the directory MUST exist if we are here! Change back to ; the current directory and return a 1. CD, currentDirectory RETURN, 1 END;********************************************************** PRO MoveData, Main=mainDir, Demo=demoDir ; This is a program to move the data files needed for the IDL training ; course into the current directory. The files are collected from the ; data directories of the IDL example and demo directories. ; Both keywords, which specify main IDL directory and the IDL Demo ; directory are required! The data is copied from the "data" directory in ; these directories to the current directory, which in most cases ; will be !Dir + 'training'. IF N_Elements(mainDir) EQ 0 THEN BEGIN check = Widget_Message(['The MAIN keyword must be used', $ 'to specify the main IDL directory.'], /Error) RETURN ENDIF IF N_Elements(demoDir) EQ 0 THEN BEGIN check = Widget_Message(['The DEMO keyword must be used', $ 'to specify the IDL DEMO directory.'], /Error) RETURN ENDIF ; Do these two directories exist? exampleExist = DirExist(mainDir) IF exampleExist EQ 0 THEN BEGIN check = Widget_Message(['The main IDL directory you supplied', $ 'with the MAIN keyword apparently', 'does not exist! Try again!'], /Error) RETURN ENDIF demoExist = DirExist(demoDir) IF demoExist EQ 0 THEN BEGIN check = Widget_Message(['The IDL DEMO directory you supplied', $ 'with the DEMO keyword apparently', 'does not exist! Try again!'], /Error) RETURN ENDIF ; Come here if an error occured. (E.G., user specified incorrect, but existing directory. Catch, error IF error NE 0 THEN BEGIN check = Widget_Message(['An error occured while reading data files.', $ 'Please check your directory names and try again!', $ '', !Err_String], /Error) RETURN ENDIF ; Get the current directory. This is where the files will go. CD, Current=currentDirectory answer = Widget_Message(['Your current directory is:', currentDirectory, 'Is this OK?'], /Question) IF StrUpCase(answer) NE 'YES' THEN RETURN ; Set up arrays to hold the file names and the file sizes so you can read ; the files and write them out in the current directory. demoFilenames = ['ctscan.dat', 'head.dat', 'worldelv.dat', 'convec.dat', 'hurric.dat', 'm51.dat', 'nyny.dat'] demoXSizes = [256, 80, 360, 248, 440, 340, 768] demoYSizes = [256, 100, 360, 248, 340, 440, 512] demoZSizes = [ 1, 57, 1, 1, 1, 1, 1 ] ; Read and write the demo files into the current directory. FOR j=0, 6 DO BEGIN file = Filepath(Root_Dir=demoDir, SubDir='data', demoFilenames(j)) data = BytArr(demoXsizes(j), demoYsizes(j), demoZsizes(j)) OpenR, lun, file, /Get_Lun Print, 'Reading file: ', file ReadU, lun, data Free_Lun, lun file = Filepath(Root_Dir=currentDirectory, demoFilenames(j)) OpenW, lun, file, /Get_Lun Print, 'Writing file: ', file WriteU, lun, data Free_Lun, lun ENDFOR exampleFilenames = ['cereb.dat', 'abnorm.dat', 'galaxy.dat', 'jet.dat', 'people.dat'] exampleXSizes = [512, 64, 256, 81, 192] exampleYSizes = [512, 64, 256, 40, 192] exampleZSizes = [ 1, 15, 1, 101, 2] ; Read and write the example files into the current directory. FOR j=0, 4 DO BEGIN file = Filepath(Root_Dir=mainDir, SubDir=['examples','data'], exampleFilenames(j)) data = BytArr(exampleXsizes(j), exampleYsizes(j), exampleZsizes(j)) OpenR, lun, file, /Get_Lun Print, 'Reading file: ', file ReadU, lun, data Free_Lun, lun file = Filepath(Root_Dir=currentDirectory, exampleFilenames(j)) OpenW, lun, file, /Get_Lun Print, 'Writing file: ', file WriteU, lun, data Free_Lun, lun ENDFOR Print,'' Print,'All files copied to the current directory successfully! END;**********************************************************