dustem_set_up_fortran.pro 2.97 KB
FUNCTION dustem_set_up_fortran,random_name=random_name,user_number=user_number

;du=dustem_set_up_fortran(/random_name,user_number=user_number)

;The idea is to modify the dustem fortran to make it run independently between users
;Method is:
;1/ modify input file that needs to be
;2/ compile fortran to a executable with a given name
;3/ modify the dustem system variables accordingly

;Please do:
;cp DM_constants.f90 DM_constants_saved.f90
;cp dustem dustem_saved
;before first use of this routine (!!)

dustem_user='dustem_user' ;default name
user_number=''
IF keyword_set(random_name) THEN BEGIN
    user_number=strtrim(long(abs(randomn(seed))*1.e5),2)
	dustem_user='dustem_user'+user_number
ENDIF

dustem_dat='/tmp/'+dustem_user
dustem_res='/tmp/'+dustem_user

;1/
;read DM_constants.f90
fortran_file_name=!DUSTEM_SOFT_DIR+'/src/'+'DM_constants.f90'
fortran_file_name_modified=!DUSTEM_SOFT_DIR+'/src/'+'DM_constants_modified.f90'

openr,unit,fortran_file_name,/get_lun
line=' '
lines=[' ']
WHILE NOT eof(unit) DO BEGIN
	readf,unit,line
	lines=[lines,line]
ENDWHILE
lines=lines[1:*]
close,unit
free_lun,unit

original_lines=lines     ;This is to be able to recompile the original dustem when over

Nlines=n_elements(lines)
search_what="data_path='"
search_length=strlen(search_what)
FOR i=0L,Nlines-1 DO BEGIN
	pos=strposmulti(lines[i],search_what,count)
	IF count NE 0 THEN BEGIN
		new_line=strmid(lines[i],0,pos[0]+search_length)
		new_line=new_line+dustem_dat
		new_line=new_line+"'"
		print,new_line
		lines[i]=new_line
		;stop
	ENDIF
ENDFOR

search_what="dir_PDR='"
search_length=strlen(search_what)
FOR i=0L,Nlines-1 DO BEGIN
	pos=strposmulti(lines[i],search_what,count)
	IF count NE 0 THEN BEGIN
		new_line=strmid(lines[i],0,pos[0]+search_length)
		new_line=new_line+dustem_dat
		new_line=new_line+"'"
		print,new_line
		lines[i]=new_line
		;stop
	ENDIF
ENDFOR

;stop

;modify DM_constants.f90
openw,unit,fortran_file_name_modified,/get_lun
FOR i=0L,Nlines-1 DO BEGIN
	printf,unit,lines[i]
ENDFOR
close,unit
free_lun,unit

stop

;move modified file into used file
str='mv '+fortran_file_name_modified+' '+fortran_file_name
message,'Issuing '+str,/cont
spawn,str

;2/ compile dustem
str='rm '+!DUSTEM_SOFT_DIR+'/src/*.o'
message,'Issuing '+str,/cont
spawn,str

str='rm '+!DUSTEM_SOFT_DIR+'/src/*.mod'
message,'Issuing '+str,/cont
spawn,str

str='rm '+!DUSTEM_SOFT_DIR+'/src/dustem*'
message,'Issuing '+str,/cont
spawn,str

;3/ compile

;str='make -f '+!DUSTEM_SOFT_DIR+'/src/Makefile'
;message,'Issuing '+str,/cont

;str='cd '+!DUSTEM_SOFT_DIR+'/src'+' & make'
str='make -C'+!DUSTEM_SOFT_DIR+'/src/'+' -f '+'Makefile'
message,'Issuing '+str,/cont
spawn,str

;rename executable

str='mv '+!DUSTEM_SOFT_DIR+'/src/dustem '+!DUSTEM_SOFT_DIR+'/src/'+dustem_user
message,'Issuing '+str,/cont

;stop

;change dustemwrap system variables
dustem_f90_name=!DUSTEM_SOFT_DIR+'/src/'+dustem_user

defsysv,'!dustem_f90_exec',dustem_f90_name
defsysv,'!DUSTEM_DAT',dustem_dat+'/'
defsysv,'!DUSTEM_RES',dustem_res+'/'

;stop

RETURN,dustem_user

END