gonum.org/v1/gonum@v0.14.0/mathext/internal/amos/amoslib/fortran.go (about) 1 // Copyright ©2016 The Gonum Authors. All rights reserved. 2 // Use of this source code is governed by a BSD-style 3 // license that can be found in the LICENSE file. 4 5 //go:build fortran 6 // +build fortran 7 8 // Package amoslib is a wrapper around the Fortran amos library. 9 // 10 // See https://www.netlib.org/amos/. It is included in the Gonum repository 11 // for testing purposes only. 12 // 13 // When using the amoslib package, the "fortran" build tag must be used. 14 // The amoslib package depends on libm.so. 15 package amoslib 16 17 /* 18 #cgo LDFLAGS: -lm 19 20 double mzabs_(double * ar, double * ai); 21 void zs1s2_(double * ZRR, double * ZRI, double * S1R, double * S1I, double * S2R, double * S2I, int* NZ, double *ASCLE, double * ALIM, int * IUF); 22 void zacai_(double * ZR, double * ZI, double * FNU, int * KODE, int * N, int * MR, double * YR, double * YI, int * NZ, double * RL, double * tol, double * elim, double * alim); 23 void zseri_(double * ZR, double * ZI, double * FNU, int * KODE, int * N, double * YR, double * YI, int * NZ, double * tol, double * elim, double * alim); 24 void zmlri_(double * ZR, double * ZI, double * FNU, int * KODE, int * N, double * YR, double * YI, int * NZ, double * tol); 25 void zbknu_(double * ZR, double * ZI, double * FNU, int * KODE, int * N, double * YR, double * YI, int * NZ, double * tol, double * elim, double * alim); 26 void zasyi_(double * ZR, double * ZI, double * FNU, int * KODE, int * N, double * YR, double * YI, int * NZ,double * RL, double * tol, double * elim, double * alim); 27 void zkscl_(double * ZRR, double * ZRI, double * FNU, int * N, double * YR, double * YI, int * NZ, double * RZR, double * RZI, double * ASCLE, double * tol, double * elim); 28 void zuchk_(double * YR, double * YI, int * NZ, double * ASCLE, double * TOL); 29 void zairy_(double * ZR, double * ZI, int * ID, int * KODE, double * AIR, double * AII, int * NZ, int * IERR); 30 void zlog_(double * ar, double * ai, double * br, double * bi, int * ierr); 31 void zexp_(double * ar, double * ai, double * br, double * bi); 32 void zsqrt_(double * ar, double * ai, double * br, double * bi); 33 void zdiv_(double * ar, double * ai, double * br, double * bi, double * cr, double * ci); 34 void zmlt_(double * ar, double * ai, double * br, double * bi, double * cr, double * ci); 35 double dgamln_(double *z, int * ierr); 36 void zshch_(double * zr, double * zi, double * cshr, double * cshi, double * cchr, double * cchi); 37 double mysqrt_(double * A); 38 double myexp_(double * A); 39 double mycos_(double * A); 40 double mysin_(double * A); 41 double mylog_(double * A); 42 double mytan_(double * A); 43 double myatan_(double * A); 44 double myabs_(double * A); 45 double mymin_(double * A, double * B); 46 double mymax_(double * A, double * B); 47 */ 48 import "C" 49 import "unsafe" 50 51 func MinFort(a, b float64) float64 { 52 ans := C.mymin_((*C.double)(&a), (*C.double)(&b)) 53 return float64(ans) 54 } 55 56 func MaxFort(a, b float64) float64 { 57 ans := C.mymax_((*C.double)(&a), (*C.double)(&b)) 58 return float64(ans) 59 } 60 61 func AbsFort(a float64) float64 { 62 ans := C.myabs_((*C.double)(&a)) 63 return float64(ans) 64 } 65 66 func AtanFort(a float64) float64 { 67 ans := C.myatan_((*C.double)(&a)) 68 return float64(ans) 69 } 70 71 func TanFort(a float64) float64 { 72 ans := C.mytan_((*C.double)(&a)) 73 return float64(ans) 74 } 75 76 func LogFort(a float64) float64 { 77 ans := C.mylog_((*C.double)(&a)) 78 return float64(ans) 79 } 80 81 func SinFort(a float64) float64 { 82 ans := C.mysin_((*C.double)(&a)) 83 return float64(ans) 84 } 85 86 func CosFort(a float64) float64 { 87 ans := C.mycos_((*C.double)(&a)) 88 return float64(ans) 89 } 90 91 func ExpFort(a float64) float64 { 92 ans := C.myexp_((*C.double)(&a)) 93 return float64(ans) 94 } 95 96 func SqrtFort(a float64) float64 { 97 ans := C.mysqrt_((*C.double)(&a)) 98 return float64(ans) 99 } 100 101 func DgamlnFort(a float64) float64 { 102 var ierr int 103 pierr := (*C.int)(unsafe.Pointer(&ierr)) 104 pa := (*C.double)(&a) 105 ans := C.dgamln_(pa, pierr) 106 return (float64)(ans) 107 } 108 109 func ZmltFort(a, b complex128) complex128 { 110 ar := real(a) 111 ai := imag(a) 112 br := real(b) 113 bi := imag(b) 114 var cr, ci float64 115 C.zmlt_( 116 (*C.double)(&ar), (*C.double)(&ai), 117 (*C.double)(&br), (*C.double)(&bi), 118 (*C.double)(&cr), (*C.double)(&ci), 119 ) 120 return complex(cr, ci) 121 } 122 123 func ZdivFort(a, b complex128) complex128 { 124 ar := real(a) 125 ai := imag(a) 126 br := real(b) 127 bi := imag(b) 128 var cr, ci float64 129 C.zdiv_( 130 (*C.double)(&ar), (*C.double)(&ai), 131 (*C.double)(&br), (*C.double)(&bi), 132 (*C.double)(&cr), (*C.double)(&ci), 133 ) 134 return complex(cr, ci) 135 } 136 137 func ZabsFort(a complex128) float64 { 138 ar := real(a) 139 ai := imag(a) 140 return float64(C.mzabs_((*C.double)(&ar), (*C.double)(&ai))) 141 } 142 143 func ZsqrtFort(a complex128) (b complex128) { 144 ar := real(a) 145 ai := imag(a) 146 147 var br, bi float64 148 149 par := (*C.double)(&ar) 150 pai := (*C.double)(&ai) 151 pbr := (*C.double)(&br) 152 pbi := (*C.double)(&bi) 153 154 C.zsqrt_(par, pai, pbr, pbi) 155 return complex(br, bi) 156 } 157 158 func ZexpFort(a complex128) (b complex128) { 159 ar := real(a) 160 ai := imag(a) 161 162 var br, bi float64 163 164 par := (*C.double)(&ar) 165 pai := (*C.double)(&ai) 166 pbr := (*C.double)(&br) 167 pbi := (*C.double)(&bi) 168 169 C.zexp_(par, pai, pbr, pbi) 170 return complex(br, bi) 171 } 172 173 func ZlogFort(a complex128) (b complex128) { 174 ar := real(a) 175 ai := imag(a) 176 var ierr int 177 var br, bi float64 178 179 par := (*C.double)(&ar) 180 pai := (*C.double)(&ai) 181 pbr := (*C.double)(&br) 182 pbi := (*C.double)(&bi) 183 pierr := (*C.int)(unsafe.Pointer(&ierr)) 184 C.zlog_(par, pai, pbr, pbi, pierr) 185 return complex(br, bi) 186 } 187 188 func Zshch(ZR, ZI, CSHR, CSHI, CCHR, CCHI float64) (ZRout, ZIout, CSHRout, CSHIout, CCHRout, CCHIout float64) { 189 pzr := (*C.double)(&ZR) 190 pzi := (*C.double)(&ZI) 191 pcshr := (*C.double)(&CSHR) 192 pcshi := (*C.double)(&CSHI) 193 pcchr := (*C.double)(&CCHR) 194 pcchi := (*C.double)(&CCHI) 195 196 C.zshch_(pzr, pzi, pcshr, pcshi, pcchr, pcchi) 197 return ZR, ZI, CSHR, CSHI, CCHR, CCHI 198 } 199 200 func ZairyFort(ZR, ZI float64, ID, KODE int) (AIR, AII float64, NZ, IERR int) { 201 pzr := (*C.double)(&ZR) 202 pzi := (*C.double)(&ZI) 203 pid := (*C.int)(unsafe.Pointer(&ID)) 204 pkode := (*C.int)(unsafe.Pointer(&KODE)) 205 206 pair := (*C.double)(&AIR) 207 paii := (*C.double)(&AII) 208 pnz := (*C.int)(unsafe.Pointer(&NZ)) 209 pierr := (*C.int)(unsafe.Pointer(&IERR)) 210 C.zairy_(pzr, pzi, pid, pkode, pair, paii, pnz, pierr) 211 212 NZ = int(*pnz) 213 IERR = int(*pierr) 214 return AIR, AII, NZ, IERR 215 } 216 217 func ZksclFort(ZRR, ZRI, FNU float64, N int, YR, YI []float64, NZ int, RZR, RZI, ASCLE, TOL, ELIM float64) ( 218 ZRout, ZIout, FNUout float64, Nout int, YRout, YIout []float64, NZout int, RZRout, RZIout, ASCLEout, TOLout, ELIMout float64) { 219 220 pzrr := (*C.double)(&ZRR) 221 pzri := (*C.double)(&ZRI) 222 pfnu := (*C.double)(&FNU) 223 pn := (*C.int)(unsafe.Pointer(&N)) 224 pyr := (*C.double)(&YR[0]) 225 pyi := (*C.double)(&YI[0]) 226 pnz := (*C.int)(unsafe.Pointer(&NZ)) 227 przr := (*C.double)(&RZR) 228 przi := (*C.double)(&RZI) 229 pascle := (*C.double)(&ASCLE) 230 ptol := (*C.double)(&TOL) 231 pelim := (*C.double)(&ELIM) 232 233 C.zkscl_(pzrr, pzri, pfnu, pn, pyr, pyi, pnz, przr, przi, pascle, ptol, pelim) 234 N = int(*pn) 235 NZ = int(*pnz) 236 return ZRR, ZRI, FNU, N, YR, YI, NZ, RZR, RZI, ASCLE, TOL, ELIM 237 } 238 239 func ZbknuFort(ZR, ZI, FNU float64, KODE, N int, YR, YI []float64, NZ int, TOL, ELIM, ALIM float64) ( 240 ZRout, ZIout, FNUout float64, KODEout, Nout int, YRout, YIout []float64, NZout int, TOLout, ELIMout, ALIMout float64) { 241 242 pzr := (*C.double)(&ZR) 243 pzi := (*C.double)(&ZI) 244 pfnu := (*C.double)(&FNU) 245 pkode := (*C.int)(unsafe.Pointer(&KODE)) 246 pn := (*C.int)(unsafe.Pointer(&N)) 247 pyr := (*C.double)(&YR[0]) 248 pyi := (*C.double)(&YI[0]) 249 pnz := (*C.int)(unsafe.Pointer(&NZ)) 250 ptol := (*C.double)(&TOL) 251 pelim := (*C.double)(&ELIM) 252 palim := (*C.double)(&ALIM) 253 254 C.zbknu_(pzr, pzi, pfnu, pkode, pn, pyr, pyi, pnz, ptol, pelim, palim) 255 KODE = int(*pkode) 256 N = int(*pn) 257 NZ = int(*pnz) 258 return ZR, ZI, FNU, KODE, N, YR, YI, NZ, TOL, ELIM, ALIM 259 } 260 261 func ZasyiFort(ZR, ZI, FNU float64, KODE, N int, YR, YI []float64, NZ int, RL, TOL, ELIM, ALIM float64) ( 262 ZRout, ZIout, FNUout float64, KODEout, Nout int, YRout, YIout []float64, NZout int, RLout, TOLout, ELIMout, ALIMout float64) { 263 264 pzr := (*C.double)(&ZR) 265 pzi := (*C.double)(&ZI) 266 pfnu := (*C.double)(&FNU) 267 pkode := (*C.int)(unsafe.Pointer(&KODE)) 268 pn := (*C.int)(unsafe.Pointer(&N)) 269 pyr := (*C.double)(&YR[0]) 270 pyi := (*C.double)(&YI[0]) 271 pnz := (*C.int)(unsafe.Pointer(&NZ)) 272 prl := (*C.double)(&RL) 273 ptol := (*C.double)(&TOL) 274 pelim := (*C.double)(&ELIM) 275 palim := (*C.double)(&ALIM) 276 277 C.zasyi_(pzr, pzi, pfnu, pkode, pn, pyr, pyi, pnz, prl, ptol, pelim, palim) 278 KODE = int(*pkode) 279 N = int(*pn) 280 NZ = int(*pnz) 281 return ZR, ZI, FNU, KODE, N, YR, YI, NZ, RL, TOL, ELIM, ALIM 282 } 283 284 func ZuchkFort(YR, YI float64, NZ int, ASCLE, TOL float64) (YRout, YIout float64, NZout int, ASCLEout, TOLout float64) { 285 pyr := (*C.double)(&YR) 286 pyi := (*C.double)(&YI) 287 pnz := (*C.int)(unsafe.Pointer(&NZ)) 288 pascle := (*C.double)(&ASCLE) 289 ptol := (*C.double)(&TOL) 290 291 C.zuchk_(pyr, pyi, pnz, pascle, ptol) 292 return YR, YI, NZ, ASCLE, TOL 293 } 294 295 func Zs1s2Fort(ZRR, ZRI, S1R, S1I, S2R, S2I float64, NZ int, ASCLE, ALIM float64, IUF int) ( 296 ZRRout, ZRIout, S1Rout, S1Iout, S2Rout, S2Iout float64, NZout int, ASCLEout, ALIMout float64, IUFout int) { 297 298 pzrr := (*C.double)(&ZRR) 299 pzri := (*C.double)(&ZRI) 300 ps1r := (*C.double)(&S1R) 301 ps1i := (*C.double)(&S1I) 302 ps2r := (*C.double)(&S2R) 303 ps2i := (*C.double)(&S2I) 304 pnz := (*C.int)(unsafe.Pointer(&NZ)) 305 pascle := (*C.double)(&ASCLE) 306 palim := (*C.double)(&ALIM) 307 piuf := (*C.int)(unsafe.Pointer(&IUF)) 308 309 C.zs1s2_(pzrr, pzri, ps1r, ps1i, ps2r, ps2i, pnz, pascle, palim, piuf) 310 return ZRR, ZRI, S1R, S1I, S2R, S2I, NZ, ASCLE, ALIM, IUF 311 } 312 313 func ZacaiFort(ZR, ZI, FNU float64, KODE, MR, N int, YR, YI []float64, NZ int, RL, TOL, ELIM, ALIM float64) ( 314 ZRout, ZIout, FNUout float64, KODEout, MRout, Nout int, YRout, YIout []float64, NZout int, RLout, TOLout, ELIMout, ALIMout float64) { 315 pzr := (*C.double)(&ZR) 316 pzi := (*C.double)(&ZI) 317 pfnu := (*C.double)(&FNU) 318 pkode := (*C.int)(unsafe.Pointer(&KODE)) 319 pmr := (*C.int)(unsafe.Pointer(&MR)) 320 pn := (*C.int)(unsafe.Pointer(&N)) 321 pyr := (*C.double)(&YR[0]) 322 pyi := (*C.double)(&YI[0]) 323 pnz := (*C.int)(unsafe.Pointer(&NZ)) 324 prl := (*C.double)(&RL) 325 ptol := (*C.double)(&TOL) 326 pelim := (*C.double)(&ELIM) 327 palim := (*C.double)(&ALIM) 328 329 C.zacai_(pzr, pzi, pfnu, pkode, pmr, pn, pyr, pyi, pnz, prl, ptol, pelim, palim) 330 KODE = int(*pkode) 331 MR = int(*pmr) 332 N = int(*pn) 333 NZ = int(*pnz) 334 return ZR, ZI, FNU, KODE, MR, N, YR, YI, NZ, RL, TOL, ELIM, ALIM 335 } 336 337 func ZseriFort(ZR, ZI, FNU float64, KODE, N int, YR, YI []float64, NZ int, TOL, ELIM, ALIM float64) ( 338 ZRout, ZIout, FNUout float64, KODEout, Nout int, YRout, YIout []float64, NZout int, TOLout, ELIMout, ALIMout float64) { 339 pzr := (*C.double)(&ZR) 340 pzi := (*C.double)(&ZI) 341 pfnu := (*C.double)(&FNU) 342 pkode := (*C.int)(unsafe.Pointer(&KODE)) 343 pn := (*C.int)(unsafe.Pointer(&N)) 344 pyr := (*C.double)(&YR[0]) 345 pyi := (*C.double)(&YI[0]) 346 pnz := (*C.int)(unsafe.Pointer(&NZ)) 347 ptol := (*C.double)(&TOL) 348 pelim := (*C.double)(&ELIM) 349 palim := (*C.double)(&ALIM) 350 351 C.zseri_(pzr, pzi, pfnu, pkode, pn, pyr, pyi, pnz, ptol, pelim, palim) 352 KODE = int(*pkode) 353 N = int(*pn) 354 NZ = int(*pnz) 355 return ZR, ZI, FNU, KODE, N, YR, YI, NZ, TOL, ELIM, ALIM 356 } 357 358 func ZmlriFort(ZR, ZI, FNU float64, KODE, N int, YR, YI []float64, NZ int, TOL float64) ( 359 ZRout, ZIout, FNUout float64, KODEout, Nout int, YRout, YIout []float64, NZout int, TOLout float64) { 360 pzr := (*C.double)(&ZR) 361 pzi := (*C.double)(&ZI) 362 pfnu := (*C.double)(&FNU) 363 pkode := (*C.int)(unsafe.Pointer(&KODE)) 364 pn := (*C.int)(unsafe.Pointer(&N)) 365 pyr := (*C.double)(&YR[0]) 366 pyi := (*C.double)(&YI[0]) 367 pnz := (*C.int)(unsafe.Pointer(&NZ)) 368 ptol := (*C.double)(&TOL) 369 370 C.zmlri_(pzr, pzi, pfnu, pkode, pn, pyr, pyi, pnz, ptol) 371 KODE = int(*pkode) 372 N = int(*pn) 373 NZ = int(*pnz) 374 return ZR, ZI, FNU, KODE, N, YR, YI, NZ, TOL 375 }