NADCON5-ng  0.0.1
NADCON5 Next Generation
xyz2b.f
Go to the documentation of this file.
1 c> \ingroup core
2 c> Part of the NADCON5 \ref core , Converts GMT `*.grd` to a `*.b` NADCON style grid file
3 c>
4 c> Turn gmt/netcdf grd dump into my grid file (real number version)
5 c> assumes grd dump is longitude/latitude/real (binary s.p.)
6 c>
7 c>
8 c> ### Program arguments
9 c> Arguments are newline terminated and read from standard input
10 c>
11 c> When run from the command line, the program prints a prompt for each argument
12 c>
13 c> They are enumerated here
14 c> \param infile Input File Name
15 c> \param outfile Output File Name
16 c>
17 c> ### Program Inputs:
18 c>
19 c> - `lin` Input File (`*.grd`)
20 c>
21 c> ### Program Outputs:
22 c>
23 c> - `lout` Output File (`*.b`)
24 c>
25  program xyz2b
26 
27 *** turn gmt/netcdf grd dump into my grid file (real number version)
28 *** assumes grd dump is longitude/latitude/real (binary s.p.)
29 
30  implicit double precision(a-h,o-z)
31  parameter(len=5401*5401)
32  parameter(gran=3600.d0)
33  character*88 fname
34  logical makpos
35  integer h(len)
36  real*4 z(len),glo,gla,val
37  equivalence(h(1),z(1))
38 
39  lin=1
40  lout=2
41 
42 **** write(*,1)
43 ****1 format(' program xyz2b --> Enter input file name: ',$)
44 **** read(*,'(a)') fname
45 
46  read(5,'(a)') fname
47 
48 *** next line is non-standard (binary input)
49 c open(lin,file='temp',status='old',form='binary')
50  open(lin,file=fname,status='old',form='binary')
51 
52 **** write(*,2)
53 ****2 format(' grid output --> Enter file name: ',$)
54 **** read(*,'(a)') fname
55 
56  read(5,'(a)') fname
57 
58 c open(lout,file='xyz2b.b',status='new',form='unformatted')
59  open(lout,file=fname,status='new',form='unformatted')
60 
61 **** write(*,'(a,$)') 'Integer data? '
62 **** read (*,'(a)') yesno
63 
64 *** real number version
65 
66  yesno='n'
67  if(yesno.eq.'y'.or.yesno.eq.'Y') then
68  ikind=0
69  else
70  ikind=1
71  endif
72 
73  glamx=-9999.d0
74  glamn= 9999.d0
75  glomx=-9999.d0
76  glomn= 9999.d0
77  dgla =-9999.d0
78  dglo =-9999.d0
79 
80 *** loop over data -- get grid parameters
81 
82  n=0
83  read(lin) glo,gla,val
84  n=1
85  if(makpos(glo)) continue
86 
87  if(gla.gt.glamx) glamx=gla
88  if(gla.lt.glamn) glamn=gla
89  if(glo.gt.glomx) glomx=glo
90  if(glo.lt.glomn) glomn=glo
91 
92  glax=gla
93  glox=glo
94 
95  100 read(lin,end=777) glo,gla,val
96  n=n+1
97  if(makpos(glo)) continue
98 
99  if(gla.gt.glamx) glamx=gla
100  if(gla.lt.glamn) glamn=gla
101  if(glo.gt.glomx) glomx=glo
102  if(glo.lt.glomn) glomn=glo
103 
104  dla=dabs(gla-glax)
105  dlo=dabs(glo-glox)
106  if(dla.gt.dgla.and.dla.lt.(glamx-glamn)/2.d0 ) dgla=dla
107  if(dlo.gt.dglo.and.dlo.lt.(glomx-glomn)/2.d0 ) dglo=dlo
108 
109  glax=gla
110  glox=glo
111  go to 100
112  777 rewind lin
113 
114 *** adjust granularity of input and report header
115 
116  glamn=idnint(gran*glamn)/gran
117  glamx=idnint(gran*glamx)/gran
118  glomn=idnint(gran*glomn)/gran
119  glomx=idnint(gran*glomx)/gran
120  dgla =idnint(gran*dgla )/gran
121  dglo =idnint(gran*dglo )/gran
122  nla=idnint((glamx-glamn)/dgla)+1
123  nlo=idnint((glomx-glomn)/dglo)+1
124  dgla=(glamx-glamn)/dble(nla-1)
125  dglo=(glomx-glomn)/dble(nlo-1)
126 
127  write(*,*)
128  write(*,*) ' kind=',ikind
129  write(*,*) ' LAT min=',glamn
130  write(*,*) ' del=',dgla,' # lat=',nla
131  write(*,*) ' max=',glamn+(nla-1)*dgla
132  write(*,*) ' LON min=',glomn
133  write(*,*) ' del=',dglo,' # lon=',nlo
134  write(*,*) ' max=',glomn+(nlo-1)*dglo
135 
136 *** initialize the grid
137 
138  if(nla*nlo.gt.len) stop 12345
139  if(ikind.eq.0) then
140  do 3 i=1,nla*nlo
141  3 h(i)=0
142  else
143  do 4 i=1,nla*nlo
144  4 z(i)=9999999999.0
145  endif
146 
147 *** read the text (3rd column is alway real*4 float)
148 
149  icount=0
150  iclip=0
151  10 read(lin,end=7777) glo,gla,val
152  icount=icount+1
153  if(makpos(glo)) continue
154  if(ikind.eq.0) then
155  ival=nint(val)
156  call put1(ival,gla,glo,h,nla,nlo,glamn,dgla,glomn,dglo,iclip)
157  else
158  call put2( val,gla,glo,z,nla,nlo,glamn,dgla,glomn,dglo,iclip)
159  endif
160  go to 10
161  7777 continue
162 
163 *** write the grid
164 
165  write(lout) glamn,glomn,dgla,dglo,nla,nlo,ikind
166  if(ikind.eq.0) then
167  call w1(lout,h,nla,nlo,glamn,dgla,glomn,dglo)
168  else
169  call w2(lout,z,nla,nlo,glamn,dgla,glomn,dglo)
170  endif
171 
172  write(*,*) ' all, icount, iclip = ',nla*nlo,icount,iclip
173 
174  stop
175  end
176  subroutine put1(ival,gla,glo,h,nla,nlo,glamn,dgla,glomn,dglo,iclp)
178 *** load value into grid
179 
180  implicit double precision(a-h,o-z)
181  real*4 val,gla,glo
182  integer h(nla,nlo)
183 
184  i=idnint((gla-glamn)/dgla)+1
185  if(i.lt.1.or.i.gt.nla) then
186  iclp=iclp+1
187  return
188  endif
189  j=idnint((glo-glomn)/dglo)+1
190  if(j.lt.1.or.j.gt.nlo) then
191  iclp=iclp+1
192  return
193  endif
194  h(i,j)=ival
195 
196  return
197  end
198  subroutine put2(val,gla,glo,z,nla,nlo,glamn,dgla,glomn,dglo,iclip)
200 *** load value into grid
201 
202  implicit double precision(a-h,o-z)
203  real*4 z(nla,nlo),val,gla,glo
204 
205  i=idnint((gla-glamn)/dgla)+1
206  if(i.lt.1.or.i.gt.nla) then
207  iclip=iclip+1
208  return
209  endif
210  j=idnint((glo-glomn)/dglo)+1
211  if(j.lt.1.or.j.gt.nlo) then
212  iclip=iclip+1
213  return
214  endif
215  z(i,j)=val
216 
217  return
218  end
219  subroutine w1(lout,h,nla,nlo,glamn,dgla,glomn,dglo)
221 *** write records south to north (elements are west to east)
222 
223  implicit double precision(a-h,o-z)
224  integer h(nla,nlo)
225 
226  do 1 i=1,nla
227  1 write(lout) (h(i,j),j=1,nlo)
228 
229  return
230  end
231  subroutine w2(lout,z,nla,nlo,glamn,dgla,glomn,dglo)
233 *** write records south to north (elements are west to east)
234 
235  implicit double precision(a-h,o-z)
236  real*4 z(nla,nlo)
237 
238  do 1 i=1,nla
239  1 write(lout) (z(i,j),j=1,nlo)
240 
241  return
242  end
243  logical function makpos(glon)
245 *** insure longitude is positive (single precision)
246 
247  makpos=.false.
248 
249  1 if(glon.lt.0.d0) then
250  glon=glon+360.d0
251  makpos=.true.
252  go to 1
253  endif
254 
255  2 if(glon.ge.360.d0) then
256  glon=glon-360.d0
257  go to 2
258  endif
259 
260  return
261  end
subroutine w1(lout, h, nla, nlo, glamn, dgla, glomn, dglo)
Definition: xyz2b.f:220
subroutine put2(val, gla, glo, z, nla, nlo, glamn, dgla, glomn, dglo, iclip)
Definition: xyz2b.f:199
logical function makpos(glon)
Definition: xyz2b.f:244
subroutine w2(lout, z, nla, nlo, glamn, dgla, glomn, dglo)
Definition: xyz2b.f:232
subroutine put1(ival, gla, glo, h, nla, nlo, glamn, dgla, glomn, dglo, iclp)
Definition: xyz2b.f:177
program xyz2b
Part of the NADCON5 NADCON5 Core Library , Converts GMT *.grd to a *.b NADCON style grid file...
Definition: xyz2b.f:25