Advertisement
Guest User

Untitled

a guest
Mar 28th, 2017
59
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 12.20 KB | None | 0 0
  1. !Model of migration of krill in Scotia sea (date 2000)
  2. !The first approximation
  3. !Pleshanov D. A. 05.2015
  4. program Migrationofkrillmodel
  5.  
  6. use ifport
  7. implicit none
  8.  
  9. integer nDay,ix,jy,kz,i1,n1,nt,i,j,iday,k,iitime,zz
  10. integer ix1,ix2,jy1,jy2,kz1,kz2
  11. integer n2, j2, jp, i2, n3, c
  12. integer p,pt,pp,jj
  13.  
  14. integer*2 s1,s2
  15. real*4 rr
  16.  
  17. !for trilinear interpolation
  18. real U11,U12,U1,V11,V12,V1
  19. real U21,U22,U2,V21,V22,V2
  20. real U31,U32,U3,V31,V32,V3
  21. real U41,U42,U4,V41,V42,V4
  22. real U51,U52,U5,V51,V52,V5
  23. real U61,U62,U6,V61,V62,V6
  24. real U71,U72,U7,V71,V72,V7
  25. real U81,U82,U8,V81,V82,V8
  26. real iix1,iix2,jjy1,jjy2,kkz1,kkz2
  27. real U,V,Ui,Vi
  28. real fi,sigma1,sigma2,a1,a2,rd
  29. real*4 rann
  30.  
  31. real iitime2,kzz,zm
  32. real dt,begX,begY,dX,dY,dZ,R,pi,A,b,Cr,nt1,crz
  33. real pointX,pointY,pointZ,dpx,dpy,dpz
  34. real pointXm,pointYm,dpointXm,dpointYm
  35. real pointXrand,pointYrand,pointZrand
  36.  
  37. character*30 infileU, infileV, inkrill, outkrill,crout, crout2
  38. character*1 inU,inV
  39. character*2 Uname2, Vname2,cr3
  40. character*3 Uname1,Vname1,cr2
  41. character*4 frmt, cr1
  42.  
  43. include 'krill.c' !file with input variables
  44. dimension U(ix,jy,kz),V(ix,jy,kz),Cr(n2,i2),crz(n2,i2)
  45.  
  46. a1=.001 !for random U and V
  47. a2=.001 !for random Z
  48. pi=3.141593
  49. !R=6371.032 !km
  50. R=6371032.0 !m
  51. !input and output file names
  52. data inU/'u'/
  53. data inV/'v'/
  54. data frmt/'.dat'/
  55. data Uname1/'U00'/
  56. data Vname1/'V00'/
  57. data Uname2/'U0'/
  58. data Vname2/'V0'/
  59. data cr1/'Cr00'/
  60. data cr2/'Cr0'/
  61. data cr3/'Cr'/
  62.  
  63. print*, 'Model of migration of krill in Scotia sea (date 2000)'
  64. print*, 'The first approximation'
  65. print*, ' '
  66. print*, 'Read input variables'
  67.  
  68. !open and read file with another variables
  69. open(1,file='Krill.ini',status='old')
  70. read(1,*) nDay
  71. read(1,*) dt
  72. read(1,*) begX
  73. read(1,*) begY
  74. read(1,*) dX
  75. read(1,*) dY
  76. read(1,*) dz
  77. read(1,*) inKrill
  78. close(1)
  79.  
  80. print*, 'Read input file with krill'
  81. open(1,file=inKrill,status='old') !read input krill data file
  82. open(2,file='krill00.dat')
  83.  
  84. do j=1,n1,1
  85. read(1,*) (Cr(j,i),i=1,i1)
  86. enddo
  87. do j=1,n1
  88. Cr(j,4)=(pi/2.)*(1.-(2.*(Cr(j,3)-1.)/zm))
  89. enddo
  90.  
  91. !write input file with krill on 0-250m
  92. print*, 'Write input file'
  93. jj=2
  94. do j2=2,200,4
  95. do j=1,n1,1
  96. jp=(jj-1)*n1+j
  97. Cr(jp,1)=Cr(j,1)
  98. Cr(jp,2)=Cr(j,2)
  99. Cr(jp,3)=j2*1.
  100. Cr(jp,4)=(pi/2.)*(1.-(2.*Cr(jp,3)/zm))
  101. enddo
  102. jj=jj+1
  103. enddo
  104.  
  105. do j=1,n2
  106. write(2,*) (Cr(j,i),i=1,4)
  107. enddo
  108.  
  109. close(1)
  110. close(2)
  111.  
  112. print*, 'Calculation began'
  113. print*, 'Write output files:'
  114. do iday=1,nDay-1 !an external step at a time
  115. !write names of input files with U and V
  116. !write names of output files
  117. if (iday.ge.1.and.iday.le.9) then
  118. write(inFileU,'(a3,i1,a4)') Uname1,iday,frmt
  119. write(inFileV,'(a3,i1,a4)') Vname1,iday,frmt
  120. write(Crout,'(a4,i1,a4)') cr1,iday,frmt
  121. else
  122. if (iday.ge.10.and.iday.le.99) then
  123. write(inFileU,'(a2,i2,a4)') Uname2,iday,frmt
  124. write(inFileV,'(a2,i2,a4)') Vname2,iday,frmt
  125. write(Crout,'(a3,i2,a4)') cr2,iday,frmt
  126. else
  127. write(inFileU,'(a1,i3,a4)') inU,iday,frmt
  128. write(inFileV,'(a1,i3,a4)') inV,iday,frmt
  129. write(Crout,'(a2,i3,a4)') cr3,iday,frmt
  130. endif
  131. endif
  132. open(1,file=inFileU,status='old')
  133. open(2,file=inFileV,status='old')
  134.  
  135. do k=1,kz,1 !read input massive with U and V
  136. do j=1,jy,1
  137. read(1,*) (U(i,j,k),i=1,ix,1)
  138. read(2,*) (V(i,j,k),i=1,ix,1)
  139. enddo
  140. enddo
  141. close(1)
  142. close(2)
  143.  
  144. !internal step at a time
  145. do iitime=0,nt,dt
  146. do i=1,n2 !for markers
  147. pointX=Cr(i,1)
  148. pointY=Cr(i,2)
  149. pointZ=Cr(i,3)
  150. fi=Cr(i,4)
  151.  
  152. !write index
  153. dpX=(pointX-begX)/dx
  154. dpY=(pointY-begY)/dy
  155. dpZ=pointZ/dz
  156.  
  157. ix1=int(dpX)+1
  158. if (ix1.ge.475) goto 404
  159. ix2=ix1+1
  160. iix1=real(ix1)-1.
  161. iix2=real(ix2)-1.
  162.  
  163. jy1=int(dpY)+1
  164. if (jy1.ge.114) goto 404
  165. jy2=jy1+1
  166. jjy1=real(jy1)-1.
  167. jjy2=real(jy2)-1.
  168.  
  169. kz1=int(dpZ)+1
  170. kz2=kz1+1
  171. kkz1=real(kz1)-1.
  172. kkz2=real(kz2)-1.
  173.  
  174. !trilinear interpolation in point
  175. !/((iix2-iix1)*(jjy2-jjy1)*(kkz2-kkz1))
  176. U11=U(ix1,jy1,kz1)
  177. U12=(iix2-dpX)*(jjy2-dpY)*(kkz2-dpz)
  178. U1=U11*U12
  179. U21=U(ix1,jy1,kz2)
  180. U22=(iix2-dpX)*(jjy2-dpY)*(dpz-kkz1)
  181. U2=U21*U22
  182. U31=U(ix1,jy2,kz1)
  183. U32=(iix2-dpX)*(dpY-jjy1)*(kkz2-dpZ)
  184. U3=U31*U32
  185. U41=U(ix1,jy2,kz2)
  186. U42=(iix2-dpX)*(dpY-jjy1)*(dpZ-kkz1)
  187. U4=U41*U42
  188. U51=U(ix2,jy1,kz1)
  189. U52=(dpX-iix1)*(jjy2-dpY)*(kkz2-dpZ)
  190. U5=U51*U52
  191. U61=U(ix2,jy1,kz2)
  192. U62=(dpX-iix1)*(jjy2-dpY)*(dpZ-kkz1)
  193. U6=U61*U62
  194. U71=U(ix2,jy2,kz1)
  195. U72=(dpX-iix1)*(dpY-jjy1)*(kkz2-dpZ)
  196. U7=U71*U72
  197. U81=U(ix2,jy2,kz2)
  198. U82=(dpX-iix1)*(dpy-jjy1)*(dpz-kkz1)
  199. U8=U81*U82
  200. Ui=(U1+U2+U3+U4+U5+U6+U7+U8) !rezalt U in point
  201.  
  202. V11=V(ix1,jy1,kz1)
  203. V12=(iix2-dpX)*(jjy2-dpY)*(kkz2-dpz)
  204. V1=V11*V12
  205. V21=U(ix1,jy1,kz2)
  206. V22=(iix2-dpX)*(jjy2-dpY)*(dpz-kkz1)
  207. V2=V21*V22
  208. V31=V(ix1,jy2,kz1)
  209. V32=(iix2-dpX)*(dpY-jjy1)*(kkz2-dpZ)
  210. V3=V31*V32
  211. V41=V(ix1,jy2,kz2)
  212. V42=(iix2-dpX)*(dpY-jjy1)*(dpZ-kkz1)
  213. V4=V41*V42
  214. V51=V(ix2,jy1,kz1)
  215. V52=(dpX-iix1)*(jjy2-dpY)*(kkz2-dpZ)
  216. V5=V51*V52
  217. V61=V(ix2,jy1,kz2)
  218. V62=(dpX-iix1)*(jjy2-dpY)*(dpZ-kkz1)
  219. V6=V61*V62
  220. V71=V(ix2,jy2,kz1)
  221. V72=(dpX-iix1)*(dpY-jjy1)*(kkz2-dpZ)
  222. V7=V71*V72
  223. V81=V(ix2,jy2,kz2)
  224. V82=(dpX-iix1)*(dpy-jjy1)*(dpz-kkz1)
  225. V8=V81*V82
  226. Vi=(V1+V2+V3+V4+V5+V6+V7+V8) !rezalt V in point
  227. if (Ui.ge.1700) then
  228. print*, begX, begY
  229. print*, U1, U3, U5, U7
  230. print*, U2, U4, U6, U8
  231. print*, pointX, pointY
  232. print*, Ui, dpX, dpY, dpZ
  233. pause 1
  234. endif
  235. if (Vi.ge.1700) then
  236. print*, begX, begY
  237. print*, V1, V3, V5, V7
  238. print*, V2, V4, V6, V8
  239. print*, pointX, pointY
  240. print*, Vi, dpX, dpY, kkz1, dpZ, kkz2
  241. pause 2
  242. endif
  243.  
  244. !convert geographic coordinates to meters
  245. pointXm=(pointX-begX)*pi/180.*R*Cos(pointY*pi/180.)
  246. pointYm=(pointY-begY)*pi/180.*R
  247.  
  248. !Random part
  249. c=1313*(iday+iitime)
  250. call seed(c)
  251. sigma1=sqrt(Ui*Ui+Vi*Vi)*dt*pi
  252. sigma2=5.*pi*dt
  253. call randu(s1,s2,rr)
  254. rd=2.*rr-1.
  255. pointXrand=sigma1*rd*a1
  256. call randu(s1,s2,rr)
  257. rd=2.*rr-1.
  258. pointYrand=sigma1*rd*a1
  259. call randu(s1,s2,rr)
  260. rd=2.*rr-1.
  261. pointZrand=sigma2*rd*a2
  262.  
  263. !calculation U and V
  264. dpointXm=Ui*dt/1000.
  265. dpointYm=Vi*dt/1000.
  266. pointXm=pointXm+dpointXm+pointXrand
  267. pointYm=pointYm+dpointYm+pointYrand
  268.  
  269. !calculation Z
  270. kzz=real(kz)
  271. iitime2=real(iitime)
  272. pointZ=125.-125.*sin((iitime2/nt1)*2.*pi+fi)+pointZrand
  273.  
  274. !convert meters to geographic coordinates
  275. pointY=(pointYm/pi)*(180./R)+begY
  276. pointX=(pointXm/pi)*(180./R)/Cos(pointY*pi/180.)+begX
  277.  
  278. if (pointY.ge.(-52.96)) pointY=-52.96
  279. if (pointX.ge.(-26.0)) pointX=-26.0
  280. if (pointY.le.(-62.0)) pointY=-62.0
  281. if (pointX.le.(-64.0)) pointX=-64.0
  282. if (pointZ.le.0.001) pointZ=0.001
  283. if (pointZ.ge.250.0) pointZ=249.9
  284.  
  285. !output massive with new dat
  286. Cr(i,1)=pointX
  287. Cr(i,2)=pointY
  288. Cr(i,3)=pointZ
  289. 404 continue
  290.  
  291. enddo
  292. enddo
  293.  
  294.  
  295. !write output data
  296. !open(1,file=Crout,status='new')
  297. !do j=1,n2,1
  298. ! write(1,*) (Cr(j,i),i=1,3,1)
  299. !enddo
  300. !close(1)
  301.  
  302. do p=0,80,10
  303. pp=1
  304. if (iday.ge.1.and.iday.le.9) then
  305. do j=1,n2,1
  306. if (Cr(j,3).gt.p.and.Cr(j,3).le.(p+10)) then
  307. pt=(p+10)/10
  308. pt=int(pt)
  309. write(Crout2,'(a4,i1,a1,i1,a4)') cr1,iday,'_',pt,frmt
  310. Crz(pp,1)=Cr(j,1)
  311. Crz(pp,2)=Cr(j,2)
  312. Crz(pp,3)=Cr(j,3)
  313. open(1,file=crout2)
  314. write(1,*) (Crz(pp,i),i=1,3)
  315. pp=pp+1
  316. endif
  317. enddo
  318. else
  319. if (iday.ge.10.and.iday.le.99) then
  320. do j=1,n2,1
  321. if (Cr(j,3).gt.p.and.Cr(j,3).le.(p+10)) then
  322. pt=(p+10)/10
  323. pt=int(pt)
  324. write(Crout2,'(a3,i2,a1,i1,a4)') cr2,iday,'_',pt,frmt
  325. Crz(pp,1)=Cr(j,1)
  326. Crz(pp,2)=Cr(j,2)
  327. Crz(pp,3)=Cr(j,3)
  328. open(1,file=crout2)
  329. write(1,*) (Crz(pp,i),i=1,3)
  330. pp=pp+1
  331. endif
  332. enddo
  333. else
  334. if (iday.ge.100.and.iday.le.999) then
  335. do j=1,n2,1
  336. if (Cr(j,3).ge.p.and.Cr(j,3).le.(p+10)) then
  337. pt=(p+10)/10
  338. pt=int(pt)
  339. write(Crout2,'(a2,i3,a1,i1,a4)') cr3,iday,'_',pt,frmt
  340. Crz(pp,1)=Cr(j,1)
  341. Crz(pp,2)=Cr(j,2)
  342. Crz(pp,3)=Cr(j,3)
  343. open(1,file=crout2)
  344. write(1,*) (Crz(pp,i),i=1,3)
  345. pp=pp+1
  346. endif
  347. enddo
  348. endif
  349. endif
  350. endif
  351. enddo
  352.  
  353. do p=90,190,10
  354. pp=1
  355. if (iday.ge.1.and.iday.le.9) then
  356. do j=1,n2,1
  357. if (Cr(j,3).gt.p.and.Cr(j,3).le.(p+10)) then
  358. pt=(p+10)/10
  359. pt=int(pt)
  360. write(Crout2,'(a4,i1,a1,i2,a4)') cr1,iday,'_',pt,frmt
  361. Crz(pp,1)=Cr(j,1)
  362. Crz(pp,2)=Cr(j,2)
  363. Crz(pp,3)=Cr(j,3)
  364. open(1,file=crout2)
  365. write(1,*) (Crz(pp,i),i=1,3)
  366. pp=pp+1
  367. endif
  368. enddo
  369. else
  370. if (iday.ge.10.and.iday.le.99) then
  371. do j=1,n2,1
  372. if (Cr(j,3).gt.p.and.Cr(j,3).le.(p+10)) then
  373. pt=(p+10)/10
  374. pt=int(pt)
  375. write(Crout2,'(a3,i2,a1,i2,a4)') cr2,iday,'_',pt,frmt
  376. Crz(pp,1)=Cr(j,1)
  377. Crz(pp,2)=Cr(j,2)
  378. Crz(pp,3)=Cr(j,3)
  379. open(1,file=crout2)
  380. write(1,*) (Crz(pp,i),i=1,3)
  381. pp=pp+1
  382. endif
  383. enddo
  384. else
  385. if (iday.ge.100.and.iday.le.999) then
  386. do j=1,n2,1
  387. if (Cr(j,3).ge.p.and.Cr(j,3).le.(p+10)) then
  388. pt=(p+10)/10
  389. pt=int(pt)
  390. write(Crout2,'(a2,i3,a1,i2,a4)') cr3,iday,'_',pt,frmt
  391. Crz(pp,1)=Cr(j,1)
  392. Crz(pp,2)=Cr(j,2)
  393. Crz(pp,3)=Cr(j,3)
  394. open(1,file=crout2)
  395. write(1,*) (Crz(pp,i),i=1,3)
  396. pp=pp+1
  397. endif
  398. enddo
  399. endif
  400. endif
  401. endif
  402. enddo
  403. print*, 'Day', iday, 'complete'
  404. enddo
  405.  
  406. print*, 'The process is completed'
  407. print*, 'Press enter to exit'
  408. read(*,*)
  409. pause
  410. endprogram
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement