Blame view

src/idl/dustem_set_up_fortran.pro 3.06 KB
5112f161   Jean-Philippe Bernard   First commit
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
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

75c2fa4b   Jean-Philippe Bernard   fixed
23
24
dustem_dat='/tmp/'+dustem_user+'/'
dustem_res='/tmp/'+dustem_user+'/'
5112f161   Jean-Philippe Bernard   First commit
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82

;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

0873e733   Jean-Philippe Bernard   fixed
83
;stop
5112f161   Jean-Philippe Bernard   First commit
84
85

;move modified file into used file
79682ce9   Jean-Philippe Bernard   fixed a bug
86
str='mv '+fortran_file_name_modified+' '+fortran_file_name
5112f161   Jean-Philippe Bernard   First commit
87
88
89
90
91
92
93
94
95
96
97
98
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

59d02e52   Jean-Philippe Bernard   fixed
99
str='rm '+!DUSTEM_SOFT_DIR+'/src/dustem'
5112f161   Jean-Philippe Bernard   First commit
100
101
102
103
104
105
106
107
message,'Issuing '+str,/cont
spawn,str

;3/ compile

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

4136ccf8   Jean-Philippe Bernard   fixed
108
;str='cd '+!DUSTEM_SOFT_DIR+'/src'+' & make'
0873e733   Jean-Philippe Bernard   fixed
109
str='make -C '+!DUSTEM_SOFT_DIR+'/src/'+' -f '+'Makefile'
5112f161   Jean-Philippe Bernard   First commit
110
111
112
113
message,'Issuing '+str,/cont
spawn,str

;rename executable
59d02e52   Jean-Philippe Bernard   fixed
114
;dustem_f90_name=!DUSTEM_SOFT_DIR+'/src/'+dustem_user
98efe83c   Jean-Philippe Bernard   fixed
115
dustem_f90_name='/tmp/'+dustem_user+'_exec'
59d02e52   Jean-Philippe Bernard   fixed
116
str='mv '+!DUSTEM_SOFT_DIR+'/src/dustem '+dustem_f90_name
5112f161   Jean-Philippe Bernard   First commit
117
message,'Issuing '+str,/cont
0873e733   Jean-Philippe Bernard   fixed
118
spawn,str
5112f161   Jean-Philippe Bernard   First commit
119
120
121
122

;stop

;change dustemwrap system variables
f2356fbf   Jean-Philippe Bernard   fixed
123
dustem_f90_name=!DUSTEM_SOFT_DIR+'/src/'+dustem_user
5112f161   Jean-Philippe Bernard   First commit
124

f2356fbf   Jean-Philippe Bernard   fixed
125
defsysv,'!dustem_f90_exec',dustem_f90_name
75c2fa4b   Jean-Philippe Bernard   fixed
126
127
defsysv,'!DUSTEM_DAT',dustem_dat
defsysv,'!DUSTEM_RES',dustem_res
5112f161   Jean-Philippe Bernard   First commit
128
129
130
131
132
133

;stop

RETURN,dustem_user

END