PRO MakeMRIImageFiles, directory Catch, theError IF theError NE 0 THEN BEGIN Catch, /Cancel ok = cgErrorMsg(/Traceback) IF N_Elements(thisDirectory) NE 0 THEN CD, thisDirectory RETURN ENDIF ; Construct a new directory if one is not passed in. IF N_Elements(directory) EQ 0 THEN BEGIN CD, Current=thisDirectory directory = FilePath(Root_Dir=thisDirectory, "mri_images") ENDIF ; Change to the new directory if it exists. If not, create it. check = Findfile(directory, Count=dirCount) IF dirCount EQ 0 THEN BEGIN File_MKDir, directory ENDIF CD, Current=thisDirectory, directory ; Open the head.dat file from the IDL examples. filename = Filepath(Subdir=['examples', 'data'], 'head.dat') OpenR, lun, filename, /Get_Lun head = BytArr(80,100,57) ReadU, lun, head Free_Lun, lun ; Write 50 files into the directory. FOR j=4, 53 DO BEGIN filename = 'image' + String(j-3, Format='(I2.2)') + '.tif' Write_Tiff, filename, Reverse(Reform(head[*,*,j]),2) ENDFOR CD, thisDirectory END