|
Last change
on this file since 24313 was 24313, checked in by Mathieu Morlighem, 6 years ago |
|
merged trunk-jpl and trunk for revision 24310
|
|
File size:
1.1 KB
|
| Line | |
|---|
| 1 | import numpy as np
|
|---|
| 2 |
|
|---|
| 3 |
|
|---|
| 4 | def vector_write(fidi, sbeg, vec, nmax, cmax):
|
|---|
| 5 | '''
|
|---|
| 6 | function to write a vector on multiple lines
|
|---|
| 7 | '''
|
|---|
| 8 | if nmax is None:
|
|---|
| 9 | nmax = np.inf
|
|---|
| 10 |
|
|---|
| 11 | if cmax is None:
|
|---|
| 12 | cmax = np.inf
|
|---|
| 13 |
|
|---|
| 14 | # set up first iteration
|
|---|
| 15 | svec = []
|
|---|
| 16 | nitem = nmax
|
|---|
| 17 | lsvec = cmax
|
|---|
| 18 |
|
|---|
| 19 | # transpose vector from column - wise to row - wise
|
|---|
| 20 | vec = np.array(vec).conj().T
|
|---|
| 21 |
|
|---|
| 22 | # assemble each line, flushing when necessary
|
|---|
| 23 | for i in range(np.size(vec, 0)):
|
|---|
| 24 |
|
|---|
| 25 | # [[1], [1], [1]...] should be [1, 1, 1, ...]
|
|---|
| 26 | if type(vec[i]) in [list, np.ndarray] and len(vec[i]) == 1:
|
|---|
| 27 | sitem = str(vec[i][0])
|
|---|
| 28 | else:
|
|---|
| 29 | sitem = str(vec[i])
|
|---|
| 30 |
|
|---|
| 31 | nitem = nitem + 1
|
|---|
| 32 | lsvec = lsvec + 1 + len(sitem)
|
|---|
| 33 |
|
|---|
| 34 | if (nitem <= nmax) and (lsvec <= cmax):
|
|---|
| 35 | svec = str(svec) + ' ' + str(sitem)
|
|---|
| 36 | else:
|
|---|
| 37 | if len(svec) > 0:
|
|---|
| 38 | fidi.write(str(svec) + '\n')
|
|---|
| 39 |
|
|---|
| 40 | svec = str(sbeg) + str(sitem)
|
|---|
| 41 | nitem = 1
|
|---|
| 42 | lsvec = len(svec)
|
|---|
| 43 |
|
|---|
| 44 | # flush buffer at , if necessary
|
|---|
| 45 | if len(svec) > 0:
|
|---|
| 46 | fidi.write(str(svec) + '\n')
|
|---|
| 47 |
|
|---|
| 48 | return
|
|---|
Note:
See
TracBrowser
for help on using the repository browser.