 |
forums.silverfrost.com Welcome to the Silverfrost forums
|
View previous topic :: View next topic |
Author |
Message |
Kenneth_Smith
Joined: 18 May 2012 Posts: 818 Location: Lanarkshire, Scotland.
|
Posted: Sat May 30, 2020 1:24 pm Post subject: |
|
|
Another thought.
Have you tried exporting the x y arrays that define the border in the call to %pl to a text file (immediately before the %pl call), and then importing that text file into Excel and plotting the data in an X-Y plot? This would confirm if %pl is correctly plotting the data that is input into it (or not). If the Excel plot is the same as the %pl plot � with crossed lines then there is an error in your code associated with reading the input data and forming the arrays that are passed to %pl. |
|
Back to top |
|
 |
Martin_K
Joined: 09 Apr 2020 Posts: 227
|
Posted: Sat May 30, 2020 7:04 pm Post subject: |
|
|
Thanks for your tip Ken!
I will inspect it as soon as I will have more time, since currently we test
a complex measuring system which we mounted on a measuring boat used for mapping of river�s bed (on Danube river) containing different sensors, sonars and GNSS equipment. I have very limited time which I can dedicate to programming. |
|
Back to top |
|
 |
Martin_K
Joined: 09 Apr 2020 Posts: 227
|
Posted: Sun May 31, 2020 2:32 pm Post subject: |
|
|
Ken,
thanks for your inspiration! I spent three nice hours in last night for checking where could be the problem regarding the joining of points with lines in my code using %PL command.
I coded it once again using a graphic Trimble Business Center utility and also Excel and definitely can say the following: neither my code nor the command %PL have the problem with respect to joining the points with lines (they do not cause the cross-line joining due to their potential internal problem)!
Definitely, the problem can be attributed to either ArcMap software of ESRI (which in some areas incorrectly split polylines to points. I will check it) OR the source of data (cadastre) has some inconsistency (incorrect order of points with respect to their coordinates). I will try to find out how to fix it. In the meantime (as time allows me) I will also strive to implement your last modification (with the direct access to a file containing a large number of arrays and their indexing) to be able to show the DX,DY values in the graphics when pointing cursor over a grid point!
Thanks again!
Martin |
|
Back to top |
|
 |
Kenneth_Smith
Joined: 18 May 2012 Posts: 818 Location: Lanarkshire, Scotland.
|
Posted: Sun May 31, 2020 6:01 pm Post subject: |
|
|
Marting,
The really important thing about using binary direct access is getting the record length correct. This demonstrates the idea.
Ken
Code: | implicit none
integer, parameter :: sp = kind(1.0), dp = kind(1.d0)
integer i, j, k
real(kind=sp) asp, bsp
real(kind=dp) adp, bdp
integer, parameter :: n = 10
! Writing two integers, two reals, two double precision reals in one record
! Two integers = 4 * 2 = 8 bytes
! Two sp reals = 4 * 2 = 8 bytes
! Two dp reals = 8 * 2 = 16 bytes
! Total = 32 bytes
open(unit=10, file='integer.bn', status='UNKNOWN', access='DIRECT', recl=32, action='write', FORM='UNFORMATTED', ERR=90 )
print*
print*
print*, 'Writing to file'
do i = 1, n
write(10,REC=i,ERR=92) i,i+1, real(i),real(i+1), dble(i), dble(i+1)
print*, i,i+1, real(i),real(i+1), dble(i), dble(i+1)
end do
close(unit=10, status='keep',ERR=91)
open(unit=11, file='integer.bn', status='unknown', access='DIRECT', recl=32, form='unformatted', err=90)
print*
print*, 'Reading from file'
do i = 1, n
read(11,REC=i,err=93) j,k,asp,bsp,adp,bdp
print*, j,k, asp, bsp, adp, bdp
end do
close(unit=11,status='keep',err=91)
open(unit=11, file='integer.bn', status='unknown', access='DIRECT', recl=32, form='unformatted', err=90)
print*
print*, 'Reading from file - random'
do i = 1, n
ii = int(dble(n)*random@())
if (ii .eq. 0) ii = 1 ! ii is random record to be accessed
read(11,REC=ii,err=93) j,k,asp,bsp,adp,bdp
print*,'Record', ii
print*, j,k, asp, bsp, adp, bdp
print*
end do
close(unit=11,status='keep',err=91)
goto 100
90 STOP 'ERROR opening direct access file'
91 STOP 'ERROR closing direct access file'
92 STOP 'ERROR writing to direct access file'
93 stop 'ERROR reading from direct access file'
100 continue
end program |
|
|
Back to top |
|
 |
Martin_K
Joined: 09 Apr 2020 Posts: 227
|
Posted: Mon Jun 01, 2020 1:55 pm Post subject: |
|
|
Ken,
I identified the problem with the joining of lines! The problem was/is in the
ArcMap export, which for unknown reasons incorrectly sorts the vertices (vertex points) created after splitting polylines into discrete set of points.
Interestingly, it can be observed in a few areas only (still stranger behaviour).
Anyway, I manually corrected the export of border points and now, in my code using the %PL command everything looks OK (see the problematic part of the graphics below, now it is OK, no cross-lines are present).
[url]
[/url]
Thanks again for your inspiration!
Finally, I can move to the implementing of your new code! |
|
Back to top |
|
 |
Martin_K
Joined: 09 Apr 2020 Posts: 227
|
Posted: Sun Jun 07, 2020 4:00 pm Post subject: |
|
|
Ken,
I finally again can devote some short time to continue my development. In your code above, there is the function LOCATE_I_J_in_TABLE(I,J,N), where N is size of an NxN matrix. It also contains the code:
Code: |
locate_i_j_in_table=(i-1)*n+j
|
I do not understand fully the code above.
My matrix is 204 (204 different values of X, they stand for rows) x 428 (428 different values of Y, they stand for columns) = 87312 (X runs in North/South direction and Y in East/West directions). The X,Y pairs have 1000m spacing (each of them) and contain the DX, DY variations. I am not sure, what should be the value N in the code above? I am not sure that the value 87312 is correct one. |
|
Back to top |
|
 |
Kenneth_Smith
Joined: 18 May 2012 Posts: 818 Location: Lanarkshire, Scotland.
|
Posted: Sun Jun 07, 2020 6:20 pm Post subject: |
|
|
Martin,
If you have a matrix of N rows and M columns, with N =2 and M =3
(1,1,) (1,2) (1,3)
(2,1) (2,2) (2,3)
If you write each element of the N x M matrix to file one element at a time BY ROW ORDER, you get:
1 (1,1)
2 (1,2)
3 (1,3)
4 (2,1)
5 (2,2)
6 (2,3)
Notice that the first three elements span M columns as does the last three elements. With this arrangement, the position of element (i,j) in the above table is: Code: | Pos(i,j) = (i-1)*M + j |
For example:
Pos(1,3) = (1-1)*3 + 3 = 3
Pos(2,3) = (2-1)*3 + 3 = 6
If you choose to write the NxM matrix to file one element at a time by COLUMN ORDER, a different look up equation needs to be used. With Column order, for the N x M matrix above, N = 2 and M = 3, there would be M spans of N rows in the output file.
Ken
Last edited by Kenneth_Smith on Sun Jun 07, 2020 9:34 pm; edited 1 time in total |
|
Back to top |
|
 |
Martin_K
Joined: 09 Apr 2020 Posts: 227
|
Posted: Sun Jun 07, 2020 7:48 pm Post subject: |
|
|
Ken,
many thanks, now it is clear (by the way, there is a misspelling error, it should be Pos(2,3) = (2-1)*3 + 3 = 6).
Again - thanks, I continue. |
|
Back to top |
|
 |
Martin_K
Joined: 09 Apr 2020 Posts: 227
|
Posted: Thu Jun 11, 2020 11:06 am Post subject: |
|
|
Ken,
I still have a problem with the locate_i_j_in_table(i,j,n) function.
I have the matrix of 204 rows x 428 columns. This I re-rewritten according to ROW order to a binary direct access file containing 87312 rows (lines) with DX,DY values (each of them 8bytes long, so RECL=16 for each row/line).
The code
Code: |
riadok_x = minloc(abs(x-xlr),1); stlpec_y = minloc(abs(y-ylr),1)
|
gives me a value of variable stlpec_y (which is in the interval between 1-428), however the value of variable riadok_x is always between 1-87312, since the sequential file with values X,Y,DX,DY from which are read the X and Y arrays was also re-written according to ROW order and also has 87312 rows/lines with X,Y,DX,DY values.
So, when using the table location equation with a value of riadok_x (say 26109, then variable stlpec_y=248), where the parameter podla_riadkov=428
Code: |
locate_i_j_in_table = (riadok_x - 1)*podla_riadkov + stlpec_y
|
then I get a very big number for the position variable riadok_x and I cannot read a binary record in the position of the variable riadok_x from the binary file containing DX,DY binary values (87312 rows/lines).
It seems to me as if the values of the variable riadok_x already define the position (number of a row) where should be read the binary DX,DY values. I tried it (to read in the DX,DY values in the position of variable riadok_x) but it works only at this concrete point, all other places (when moving with mouse in graphics) show zeros for DX,DY values.
Where am I wrong with defining the correct position in my matrix? |
|
Back to top |
|
 |
Kenneth_Smith
Joined: 18 May 2012 Posts: 818 Location: Lanarkshire, Scotland.
|
Posted: Thu Jun 11, 2020 12:27 pm Post subject: |
|
|
Martin,
The X,Y data that define the grid can easily be stored as two arrays, as before � with no memory problems. You don�t need to include this data in the direct access file.
For a given cursor position you can interrogate X and Y arrays to find the nearest grid point at X(i) and Y(j) again as before, and once you know i and j, then read the appropriate line in the direct access file. I think you are making your program too complex.
You may want to consider changing the direct access file from UNFORMATTED to FORMATTED. This would allow you to read the file in notepad for example.
If you want to run your code with the direct access file FORMATTED, you need to pay attention to the format codes for both the write and read operations � they must be the same, and the number of characters they write must be the record length.
I will post a modified version of the direct access example above using FORMATTED access shortly.
Ken |
|
Back to top |
|
 |
Martin_K
Joined: 09 Apr 2020 Posts: 227
|
Posted: Thu Jun 11, 2020 12:47 pm Post subject: |
|
|
Ken,
just for clarification:
I created the binary file containing the binary DX,DY values (and only DX,DY values) separately in a single separate program to have the binary file available for any additional purposes in the future. The binary file was created from the ASCII file containing the X,Y,DX,DY arrays, where only DX,DY values were written to the binary file. So both file have the same number of lines (87312), but binary file contains only DX,DY arrays.
So, my graphical program opens a sequential (ASCII) file containing the X,Y, DX, DY arrays to plot them in a graph and upon reading in the whole X,Y arrays from the ASCII file I also open the binary file where I want to read in the corresponding i,j record of DX,DY values determined from the X,Y arrays of the ASCII file to be able to show the X,Y,DX,DY values at the cursor position iwhen moving with the cursor n the graphics. |
|
Back to top |
|
 |
Kenneth_Smith
Joined: 18 May 2012 Posts: 818 Location: Lanarkshire, Scotland.
|
Posted: Thu Jun 11, 2020 1:15 pm Post subject: |
|
|
Example as promised.
Code: | implicit none
integer, parameter :: sp = kind(1.0), dp = kind(1.d0)
integer ii, i, j, k
real(kind=sp) asp, bsp
real(kind=dp) adp, bdp
integer, parameter :: n = 10
character(len=50), parameter :: fmt='(I3,1X,I3,1X,F10.5,1X,1X,F10.5,1X,F10.5,1X,F10.5)'
! Note that the format code above will write out a string 52 characters long, so this is now the MINIMUM record length
!
! Integer 3 characters
! One space 1
! Integer 3
! One space 1
! Real 10
! One space 1
! Real 10
! One space 1
! Real 10
! One space 1
! Real 10
! ------
! Total width 52
! ------
open(unit=10, file='martin.txt', status='UNKNOWN', access='DIRECT', recl=52, action='WRITE', FORM='FORMATTED', ERR=90 )
print*
print*, 'Writing to file'
do i = 1, n
write(10,fmt,REC=i,ERR=92) i,i+10, real(i),real(i)+1.0, dble(i), dble(i) + 1.d0
write(6,fmt) i,i+10, real(i),real(i)+1.0, dble(i), dble(i) + 1.d0 ! Echo to screen
end do
close(unit=10, status='keep',ERR=91)
! Open the direct access file
open(unit=11, file='martin.txt', status='OLD', access='DIRECT', recl=52, action='READ', form='FORMATTED', err=90)
print*
print*, 'Reading from file'
do i = 1, n
read(11,fmt,REC=i,err=93) j,k,asp,bsp,adp,bdp
write(6,fmt) j,k, asp, bsp, adp, bdp ! Echo to screen
end do
close(unit=11,status='keep',err=91)
open(unit=11, file='martin.txt', status='OLD', access='DIRECT', recl=52, action='READ', form='FORMATTED', err=90)
print*
print*, 'Reading from file - n random records'
do i = 1, n
ii = int(dble(n)*random@())
if (ii .eq. 0) ii = 1 ! ii is random record to be accessed
read(11,fmt,REC=ii,err=93) j,k,asp,bsp,adp,bdp
print*,'Record', ii
write(6,fmt) j,k, asp, bsp, adp, bdp
end do
close(unit=11,status='keep',err=91)
goto 100
90 STOP 'ERROR opening direct access file'
91 STOP 'ERROR closing direct access file'
92 STOP 'ERROR writing to direct access file'
93 stop 'ERROR reading from direct access file'
100 continue
end program |
|
|
Back to top |
|
 |
Kenneth_Smith
Joined: 18 May 2012 Posts: 818 Location: Lanarkshire, Scotland.
|
Posted: Thu Jun 11, 2020 1:31 pm Post subject: |
|
|
Suggest you modify your code to include a write to a direct formatted file immediately after your write to the existing direct unformatted file. You will then be able to check that the data written to the binary file is as expected and looking at the "equivalent" text file.
Unformatted direct binary read/write will be faster than formatted, but it's difficult to find the bugs.
Ken |
|
Back to top |
|
 |
Martin_K
Joined: 09 Apr 2020 Posts: 227
|
Posted: Thu Jun 11, 2020 2:24 pm Post subject: |
|
|
Thanks Ken!
I will review it and try to implement! |
|
Back to top |
|
 |
Kenneth_Smith
Joined: 18 May 2012 Posts: 818 Location: Lanarkshire, Scotland.
|
Posted: Thu Jun 11, 2020 2:28 pm Post subject: |
|
|
OK I see your issue now, and it does not appear to be with the direct file.
Minloc should return a value between 1 and 204 for one axis and between 1 and 428 for the other, and there are 204 x 428 = 87,312 records in the binary file.
I don�t understand how minloc can return a value of 87,312 - unless you have read 87,312 points into the X and Y arrays from your input ascii file?
You only need 428 and 204 sets of sequential "axis" coordinates in these arrays.
Ken |
|
Back to top |
|
 |
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum
|
Powered by phpBB © 2001, 2005 phpBB Group
|