NADCON5-ng  0.0.2
NADCON5 Next Generation Documentation
myrms.f
Go to the documentation of this file.
1 c> \ingroup doers
2 c> \if MANPAGE
3 c> \page myrms
4 c> \endif
5 c>
6 c> Part of the NADCON5 build process, generates `gmtbat05`
7 c>
8 c> Creates a batch file called
9 c>
10 c> gmtbat05.(olddtm).(newdtm).(region).(igridsec)
11 c>
12 c>
13 c> Program to
14 c> 1. Run a customized RMS-computing
15 c> algorithm on vector differences (gridded minus true)
16 c> 2. Save the RMS data to GMT-ready plottable files
17 c> 3. Create a GMT batch file to plot both the
18 c> thinned data and removed data in both coverage and vectors
19 c>
20 c> Unlike "mymedian5.f", this program is
21 c> set up to compute the RMS of vector differences
22 c> in a cell-by-cell basis (aka NOT a median filter
23 c> at all, but a true RMS representation of of disagreements)
24 c>
25 c> A "value" is the differential vector of:
26 c>
27 c> interpolated-from-grid minus true
28 c>
29 c> For any cell with at least ONE point with a value, the following is done:
30 c> 1. Compute the average latitude of all points in the cell
31 c> 2. Compute the average longitude of all points in the cell
32 c> 3. Compute the RMS of all values in the cell
33 c>
34 c> The output vector will then reflect these three values.
35 c>
36 c> For latitude and ellipsoid height, the azimuth of the vector
37 c> will ALWAYS be 0.0 (pointing up) while for longitude it will
38 c> always be 90.0 (pointing right). However, these are mere conventions
39 c> as they are not directional vectors anyway, but rather quanta which
40 c> will be gridded and it is the grid which is of utmost importance.
41 c>
42 c> No PIDS will be in the output files, as the output RMS vectors are
43 c> not reflective of any one point, but rather a cell-wide conglomeration
44 c> of information.
45 c>
46 c> See DRU-11, p. 130
47 c>
48 c> ### Program arguments
49 c> Arguments are newline terminated and read from standard input
50 c>
51 c> They are enumerated here
52 c> \param oldtm Source Datum
53 c> \param newdtm Target Datum,region
54 c> \param region Conversion Region
55 c> \param agridsec Grid Spacing in arcsec
56 c>
57 c> Example:
58 c>
59 c> olddatum = 'ussd'
60 c> newdatum = 'nad27'
61 c> region = 'conus'
62 c> agridsec = '900'
63 c>
64 c> ### Program Inputs:
65 c>
66 c> ## Changelog
67 c>
68 c> ### 2016 01 21:
69 c> Updated to RETURN to an old way of registering RMS vectors
70 c> at AVE lat/lon rather than center of cell.
71 c>
72 c> ### 2015 10 28
73 c> Updated to work with new naming scheme (see DRU-11, p. 150) and
74 c> to adopt the central lat/lon for the RMS vectors, rather than
75 c> ave lat/ave lon (see DRU-11, p.145), and to also set up the gridding
76 c> of RMS vectors at the T=0.9 level (see DRU-11, p. 148)
77 c>
78 c> Also added "donzd" functionality to help control the magnitude
79 c> of the Length of Reference Vector on Ground variables.
80 c>
81 c> Also, added a section at the end to create the TOTAL error grids.
82 c> by RMS-combining the "method noise grid" (the "d3" grid)
83 c> with the "data noise grid" (the "rdd...09" grid) into
84 c> one single "transformation error grid"
85 c>
86 c> ### 2016 08 25:
87 c> For reasons that are difficult to describe, "donzd" is
88 c> now "onzd2.f" in /home/dru/Subs. Change and recompile...
89 c>
90 c> ### 2015 10 09:
91 c> Updated to add HOR vectors
92 c>
93 c> ### 2015 10 06:
94 c> Updated
95 c>
96 c> ### 2015 09 16:
97 c> Initial Release, For use in creating NADCON5
98 c> Built by Dru Smith
99 c>
100 c>
101  program myrms
102 
103  implicit real*8(a-h,o-z)
104 
105 c - Allow up to 280,000 points to come in
106 c - which also translates to letting 280,000 grid cells
107 c - to be non-empty.
108  parameter(max=280000)
109 
110 c - And using a little hit or miss logic, the number
111 c - of possible points in one cell can't be more than
112 c - about 5000, right?
113  parameter(maxppcell=5000)
114 
115 c - Holding place for each record, in read-order
116  character*80 cards(max)
117  real*8 xlat(max),xlon(max),z0(max),zm(max)
118 
119 c - Index of what latititude row and longitude column
120 c - is associated with each non-empty cell, in
121 c - cell-found order.
122 c - 1 <= ilapcell() <= nla
123 c - 1 <= ilopcell() <= nlo
124  integer*4 ilapcell(max),ilopcell(max)
125  integer*4 poscode(max)
126  integer*4 indx(max)
127 c - Distance of a point from its cell's center
128  real*8 dist(max)
129 
130 c - Index telling me which cell a given point is
131 c - associated with, in read-order
132 c - 1 <= whichcell() <= ncells
133  integer*4 whichcell(max)
134 
135 c - ppcell(i) contains the count of how many values fall
136 c - in cell "i", where "i" ratchets up from 1 to max
137 c - every time I find a new non-empty cell.
138  integer*4 ppcell(max)
139 
140  character*10 olddtm,newdtm,region
141  character*200 suffix1,suffix2
142  character*200 suffix2t04,suffix2t09,suffix2d3
143 
144 c - Input GMT-ready differentical vector files containing all points:
145  character*200 gfnvmaddlat,gfnvmaddlon,gfnvmaddeht
146  character*200 gfnvsaddlat,gfnvsaddlon
147  character*200 gfnvsaddhor,gfnvmaddhor ! 2015 10 09
148 c - Output GMT-ready RMS differential vector files:
149  character*200 gfnvmrddlat,gfnvmrddlon,gfnvmrddeht
150  character*200 gfnvsrddlat,gfnvsrddlon
151  character*200 gfnvsrddhor,gfnvmrddhor ! 2015 10 09
152 c - Output RMS GMT(surface)-ready RMS differential vector files:
153  character*200 gfnsmrddlat,gfnsmrddlon,gfnsmrddeht
154  character*200 gfnssrddlat,gfnssrddlon
155 c - Output RMS GMT-read RMS differential vector COVERAGE files:
156  character*200 gfncvrddlat,gfncvrddlon,gfncvrddeht
157 c - To be created ".grd" files by surface
158  character*200 rfnvmrddlat,rfnvmrddlon,rfnvmrddeht
159  character*200 rfnvsrddlat,rfnvsrddlon
160 c - To be created ".xyz" files by GMT's grd2xyz program
161  character*200 zfnvmrddlat,zfnvmrddlon,zfnvmrddeht
162  character*200 zfnvsrddlat,zfnvsrddlon
163 c - To be created ".b" files by grd2b
164  character*200 bfnvmrddlat,bfnvmrddlon,bfnvmrddeht
165  character*200 bfnvsrddlat,bfnvsrddlon
166 c - Stats file name
167  character*200 sfn
168  logical*1 nothinlat,nothinlon,nothineht
169 
170 c - "Method Noise" grids:
171  character*200 sadbfnvmtcdlat1000,sadbfnvmtcdlon1000
172  character*200 sadbfnvmtcdeht1000
173  character*200 sadbfnvstcdlat1000,sadbfnvstcdlon1000
174 c -" Total Error" grids in ".b" format:
175  character*200 bfnvsetelat,bfnvsetelon
176  character*200 bfnvmetelat,bfnvmetelon
177  character*200 bfnvmeteeht
178 c -" Total Error" grids in "grd" format:
179  character*200 rfnvsetelat,rfnvsetelon
180  character*200 rfnvmetelat,rfnvmetelon
181  character*200 rfnvmeteeht
182 
183 
184 c - Dummy
185  character*200 fused,gfndv,gfnsu
186 c - Output GMT-batch file:
187  character*200 gmtfile
188 c - Grid spacing, converted to characters for file names
189 c - Presumes:
190 c - 1) igridsec is an integer
191 c - 2) 1 <= igridsec <= 99999
192  integer*4 igridsec
193  character*5 agridsec
194 
195  character*6 pid
196  character*80 card
197 
198  real*8 lorvopc,lorvog0,lorvogm
199  real*8 lorvoghorddm,lorvoghordds
200 
201  real*8 basedd(5)
202 
203 c --------------------------------------
204 c --------------------------------------
205 c --------------------------------------
206 c -------BEGIN GUTS OF PROGRAM----------
207 c --------------------------------------
208 c --------------------------------------
209 c --------------------------------------
210  write(6,1001)
211  1001 format('BEGIN program myrms.f')
212 
213 c ------------------------------------------------------------------
214 c - Some required constants.
215 c ------------------------------------------------------------------
216  lorvopc = 1.d0
217  pi = 2.d0*dasin(1.d0)
218  d2r = pi/180.d0
219  re = 6371000.d0
220  s2m = (1/3600.d0)*d2r*re
221  multiplierlorvog = 2
222 
223 c ------------------------------------------------------------------
224 c - Read in arguments from batch file
225 c ------------------------------------------------------------------
226  read(5,'(a)')olddtm
227  read(5,'(a)')newdtm
228  read(5,'(a)')region
229  read(5,'(a)')agridsec
230 
231 c ------------------------------------------------------------------
232 c - Generate the suffixes used in all our files
233 c ------------------------------------------------------------------
234  read(agridsec,*)igridsec
235  suffix1=trim(olddtm)//'.'//trim(newdtm)//'.'//trim(region)
236  suffix2=trim(suffix1)//'.'//trim(agridsec)
237  suffix2t04=trim(suffix2)//'.04'
238  suffix2t09=trim(suffix2)//'.09'
239  suffix2d3=trim(suffix2)//'.d3'
240 
241 c ------------------------------------------------------------------
242 c - Open the GMT batch file for gridding the RMS data
243 c ------------------------------------------------------------------
244  gmtfile = 'gmtbat05.'//trim(suffix2)
245  open(99,file=gmtfile,status='new',form='formatted')
246  write(6,1011)trim(gmtfile)
247  1011 format(6x,'myrms.f: Creating GMT batch file ',a)
248  write(99,1030)trim(gmtfile)
249  1030 format('echo BEGIN batch file ',a)
250 
251 
252 c ------------------------------------------------------------------
253 c - Open the "dvstats" file generated by "checkgrid", and use it
254 c - to determine which, if any, elements (lat, lon, eht) to skip
255 c ------------------------------------------------------------------
256  sfn = 'dvstats.'//trim(suffix2)
257  open(2,file=sfn,status='old',form='formatted')
258  write(6,1003)trim(sfn)
259  1003 format(6x,'myrms.f: Opening exisiting stats file ',a)
260  read(2,*)nlat,rmslat
261  read(2,*)nlon,rmslon
262  read(2,*)neht,rmseht
263  nothinlat = .false.
264  nothinlon = .false.
265  nothineht = .false.
266  if(nlat.eq.0)nothinlat=.true.
267  if(nlon.eq.0)nothinlon=.true.
268  if(neht.eq.0)nothineht=.true.
269 
270 c ------------------------------------------------------------------
271 c - Open the input, raw, differential vector GMT-ready files
272 c - Note, unlike "mymedian5", these file names already
273 c - contain the grid spacing, since they refer to differences
274 c - relative to a grid that is grid-spacing dependent.
275 c ------------------------------------------------------------------
276  if(.not.nothinlat)then
277  gfnvsaddlat = 'vsaddlat.'//trim(suffix2)
278  open(21,file=gfnvsaddlat,status='old',form='formatted')
279  write(6,1010)trim(gfnvsaddlat)
280 
281  gfnvmaddlat = 'vmaddlat.'//trim(suffix2)
282  open(26,file=gfnvmaddlat,status='old',form='formatted')
283  write(6,1010)trim(gfnvmaddlat)
284  endif
285 
286  if(.not.nothinlon)then
287  gfnvsaddlon = 'vsaddlon.'//trim(suffix2)
288  open(22,file=gfnvsaddlon,status='old',form='formatted')
289  write(6,1010)trim(gfnvsaddlon)
290 
291  gfnvmaddlon = 'vmaddlon.'//trim(suffix2)
292  open(27,file=gfnvmaddlon,status='old',form='formatted')
293  write(6,1010)trim(gfnvmaddlon)
294  endif
295 
296  if(.not.nothineht)then
297  gfnvmaddeht = 'vmaddeht.'//trim(suffix2)
298  open(23,file=gfnvmaddeht,status='old',form='formatted')
299  write(6,1010)trim(gfnvmaddeht)
300  endif
301 
302  if(.not.nothinlat .and. .not.nothinlon)then
303  gfnvsaddhor = 'vsaddhor.'//trim(suffix2)
304  open(24,file=gfnvsaddhor,status='old',form='formatted')
305  write(6,1010)trim(gfnvsaddhor)
306 
307  gfnvmaddhor = 'vmaddhor.'//trim(suffix2)
308  open(25,file=gfnvmaddhor,status='old',form='formatted')
309  write(6,1010)trim(gfnvmaddhor)
310  endif
311 
312  1010 format(6x,'myrms.f: ',
313  *'Opening existing raw differential vector file ',a)
314 
315 c ------------------------------------------------------------------
316 c - Open the output, RMS'd, GMT-ready DIFFERENTIAL VECTOR files
317 c - "r" means "rms of differential"
318 c ------------------------------------------------------------------
319  if(.not.nothinlat)then
320  gfnvsrddlat = 'vsrddlat.'//trim(suffix2)
321  open(41,file=gfnvsrddlat,status='new',form='formatted')
322  write(6,1012)trim(gfnvsrddlat)
323 
324  gfnvmrddlat = 'vmrddlat.'//trim(suffix2)
325  open(46,file=gfnvmrddlat,status='new',form='formatted')
326  write(6,1012)trim(gfnvmrddlat)
327  endif
328 
329  if(.not.nothinlon)then
330  gfnvsrddlon = 'vsrddlon.'//trim(suffix2)
331  open(42,file=gfnvsrddlon,status='new',form='formatted')
332  write(6,1012)trim(gfnvsrddlon)
333 
334  gfnvmrddlon = 'vmrddlon.'//trim(suffix2)
335  open(47,file=gfnvmrddlon,status='new',form='formatted')
336  write(6,1012)trim(gfnvmrddlon)
337  endif
338 
339  if(.not.nothineht)then
340  gfnvmrddeht = 'vmrddeht.'//trim(suffix2)
341  open(43,file=gfnvmrddeht,status='new',form='formatted')
342  write(6,1012)trim(gfnvmrddeht)
343  endif
344 
345  if(.not.nothinlat .and. .not.nothinlon)then
346  gfnvsrddhor = 'vsrddhor.'//trim(suffix2)
347  open(44,file=gfnvsrddhor,status='new',form='formatted')
348  write(6,1010)trim(gfnvsrddhor)
349 
350  gfnvmrddhor = 'vmrddhor.'//trim(suffix2)
351  open(45,file=gfnvmrddhor,status='new',form='formatted')
352  write(6,1010)trim(gfnvmrddhor)
353  endif
354 
355  1012 format(6x,'myrms.f: ',
356  *'Opening output RMS differential vector file ',a)
357 
358 c ------------------------------------------------------------------
359 c - Open the output, RMS'd, GMT-ready differential COVERAGE files
360 c - "r" means "rms of differential"
361 c ------------------------------------------------------------------
362  if(.not.nothinlat)then
363  gfncvrddlat = 'cvrddlat.'//trim(suffix2)
364  open(51,file=gfncvrddlat,status='new',form='formatted')
365  write(6,1013)trim(gfncvrddlat)
366  endif
367 
368  if(.not.nothinlon)then
369  gfncvrddlon = 'cvrddlon.'//trim(suffix2)
370  open(52,file=gfncvrddlon,status='new',form='formatted')
371  write(6,1013)trim(gfncvrddlon)
372  endif
373 
374  if(.not.nothineht)then
375  gfncvrddeht = 'cvrddeht.'//trim(suffix2)
376  open(53,file=gfncvrddeht,status='new',form='formatted')
377  write(6,1013)trim(gfncvrddeht)
378  endif
379 
380  1013 format(6x,'myrms.f: ',
381  *'Opening output RMS differential coverage file ',a)
382 
383 c ------------------------------------------------------------------
384 c - Open the output, RMS'd GMT-ready files for pushing
385 c - through "surface" to get a grid.
386 c - "r" meaning "RMS'd"
387 c ------------------------------------------------------------------
388  if(.not.nothinlat)then
389  gfnssrddlat = 'ssrddlat.'//trim(suffix2)
390  open(71,file=gfnssrddlat,status='new',form='formatted')
391  write(6,1014)trim(gfnssrddlat)
392 
393  gfnsmrddlat = 'smrddlat.'//trim(suffix2)
394  open(76,file=gfnsmrddlat,status='new',form='formatted')
395  write(6,1014)trim(gfnsmrddlat)
396  endif
397 
398  if(.not.nothinlon)then
399  gfnssrddlon = 'ssrddlon.'//trim(suffix2)
400  open(72,file=gfnssrddlon,status='new',form='formatted')
401  write(6,1014)trim(gfnssrddlon)
402 
403  gfnsmrddlon = 'smrddlon.'//trim(suffix2)
404  open(77,file=gfnsmrddlon,status='new',form='formatted')
405  write(6,1014)trim(gfnsmrddlon)
406  endif
407 
408  if(.not.nothineht)then
409  gfnsmrddeht = 'smrddeht.'//trim(suffix2)
410  open(73,file=gfnsmrddeht,status='new',form='formatted')
411  write(6,1014)trim(gfnsmrddeht)
412  endif
413 
414  1014 format(6x,'myrms.f: ',
415  *'Opening output RMS differential vector ',
416  *'file (for surface):',a)
417 
418 c ------------------------------------------------------------------
419 c - Each region has officially chosen boundaries (which may
420 c - or may not agree with the MAP boundaries). Get the
421 c - official grid boundaries here. See DRU-11, p. 126
422 c ------------------------------------------------------------------
423  call getgridbounds(region,glamx,glamn,glomn,glomx)
424 
425  write(6,1004)trim(region),glamn,glamx,glomn,glomx
426  1004 format(6x,'myrms.f: Region= ',a,/,
427  * 6x,'myrms.f: North = ',f12.6,/,
428  * 6x,'myrms.f: South = ',f12.6,/,
429  * 6x,'myrms.f: West = ',f12.6,/,
430  * 6x,'myrms.f: East = ',f12.6)
431 
432 c -------------------------------------------------------
433 c - Get the header information necessary for a ".b" file
434 c - 1) Convert "igridsec" to decimal degrees
435 c - 2) Count rows and columns
436 c -------------------------------------------------------
437  dgla = dble(igridsec)/3600.d0
438  dglo = dble(igridsec)/3600.d0
439 
440  nla=idnint((glamx-glamn)/dgla)+1
441  nlo=idnint((glomx-glomn)/dglo)+1
442 
443  write(6,3001)glamn,glamx,glomn,glomx,dgla,dglo,nla,nlo
444  3001 format(6x,'myrms.f Cell Structure:',/,
445  *8x,'North = ',f16.10,/,
446  *8x,'South = ',f16.10,/,
447  *8x,'West = ',f16.10,/,
448  *8x,'East = ',f16.10,/,
449  *8x,'DLat = ',f16.10,/,
450  *8x,'DLon = ',f16.10,/,
451  *8x,'NLat = ',i16 ,/,
452  *8x,'NLon = ',i16 )
453 
454 c glamx=glamn+dgla*(nla-1) !*** register the far boundary
455 c glomx=glomn+dglo*(nlo-1)
456 
457 c -----------------------------------------------------------------------
458 c -----------------------------------------------------------------------
459 c -----------------------------------------------------------------------
460 c -----------------------------------------------------------------------
461 c - MAIN LOOP
462 c - First trip is to process on differential
463 c - latitude vectors (both units). Second trip
464 c - on differential longitude vectors (both units).
465 c - Third trip on differential ellipsoid height vectors (meters only).
466 c - What's done in each trip:
467 c - 1) Data are sorted into respective cells
468 c - 2) An overall RMS value for the whole dataset is tallied
469 c - 3) After all data are in RAM, each cell's average latitude,
470 c - average longitude and RMS value are computed
471 c - 4) The data in #3 is put (including proper scaling, based on
472 c - the overall RMS value) into a vector plot file
473 c - 5) The data in #3 is put (no scaling necessary) into a
474 c - file ready to go into surface for gridding.
475 c -----------------------------------------------------------------------
476 c -----------------------------------------------------------------------
477 c -----------------------------------------------------------------------
478 c -----------------------------------------------------------------------
479 
480  nrmslat = 0
481  nrmslon = 0
482  nrmseht = 0
483 
484  do 2001 iloop = 1,3
485 
486  if(iloop.eq.1)then
487  write(6,2002)trim(gfnvsrddlat)
488  write(6,2002)trim(gfnvmrddlat)
489  endif
490  if(iloop.eq.2)then
491  write(6,2002)trim(gfnvsrddlon)
492  write(6,2002)trim(gfnvmrddlon)
493  endif
494  if(iloop.eq.3)then
495  write(6,2002)trim(gfnvmrddeht)
496  endif
497 
498  if(iloop.eq.1 .and. nothinlat)goto 2001
499  if(iloop.eq.2 .and. nothinlon)goto 2001
500  if(iloop.eq.3 .and. nothineht)goto 2001
501 
502  lin = 20 + iloop
503 
504  if(iloop.eq.1 .or. iloop.eq.3)az=0.d0
505  if(iloop.eq.2 )az=90.d0
506 
507  2002 format(6x,'myrms.f : RMS computing on file :',a)
508 
509 
510 c 101 format(f16.10,1x,f15.10,1x,6x ,1x,12x ,1x,5x ,1x,f9.5,1x,a6)
511 c - To pull arcseconds:
512  101 format(f16.10,1x,f15.10,1x, 6x,1x, 12x,1x,f9.5,1x, 9x,1x,a6)
513 c - To pull meters:
514  1101 format(f16.10,1x,f15.10,1x, 6x,1x, 12x,1x, 9x,1x,f9.3,1x,a6)
515 
516 
517 
518  2003 format(6x,'myrms.f : Point outside boundaries: ',
519  * f16.10,1x,f15.10,1x,f9.5,1x,a6)
520 
521 c - Set the count of how many values are in each non-empty
522 c - grid cell to zero, as well as the count of how many cells
523 c - have data to zero
524  do 201 i=1,max
525  ppcell(i)=0
526  201 continue
527  ncells = 0
528 
529 c - Top of READ loop
530 c - "ikt" is the count of all records in the vector file
531 c - whether we keep them or not. "ipid" is the count
532 c - points found that are inside our grid boundaries.
533  ikt = 0
534  ipid = 0
535 
536 c - rmsoverallm is the RMS of all vectors in one file,
537 c - converted into meters.
538  rmsoverallm = 0.d0
539 
540  100 read(lin,'(a)',end=777)card
541  if(iloop.le.2)read(card, 101)glo,gla,z,pid
542  if(iloop.eq.3)read(card,1101)glo,gla,z,pid
543  ikt = ikt + 1
544 
545 c - Store the read data and values both
546  cards(ikt) = card
547 c - z0 = primary coordinates
548  z0(ikt) = z
549  xlat(ikt) = gla
550  xlon(ikt) = glo
551  if (iloop.eq.1)then
552  zm(ikt) = z * s2m
553  elseif(iloop.eq.2)then
554  coslat = dcos(gla*d2r)
555  zm(ikt) = z * s2m * coslat
556  else
557  zm(ikt)= z
558  endif
559  rms0 = rms0 + z0(ikt)**2
560  rmsm = rmsm + zm(ikt)**2
561 
562 c - Double check that the data we're using is inside our
563 c - pre-arranged grid boundaries for this region
564  if(gla.lt.glamn.or.gla.gt.glamx .or.
565  * glo.lt.glomn.or.glo.gt.glomx) then
566  write(6,2003)gla,glo,z,pid
567  goto 100
568  endif
569 
570  ipid = ipid + 1
571 
572 c - Determine which row and column our point falls in. Then
573 c - convert that combination of row/col into a single
574 c - value (encoded as ila*100000+ilo)
575  ila=idnint((gla-glamn)/dgla)+1
576  ilo=idnint((glo-glomn)/dglo)+1
577  ipos=ila*100000+ilo
578 
579 c - Is this point a new cell?
580  do 202 j=1,ncells
581 
582 c - OLD cell
583 c - Ratchet up the count of points in this cell
584 c - Store the unique input number as being in this cell
585 c - Jump out
586  if(ipos.eq.poscode(j))then
587  ppcell(j) = ppcell(j) + 1
588  whichcell(ikt) = j
589  goto 203
590  endif
591  202 continue
592 
593 c - NEW cell (jump over this code from previous loop if
594 c - an old cell were found)
595 
596  ncells = ncells + 1
597  poscode(ncells) = ipos
598  ilapcell(ncells) = ila
599  ilopcell(ncells) = ilo
600  ppcell(ncells) = 1
601  whichcell(ikt) = ncells
602 
603  203 continue
604 
605  goto 100
606 
607  777 continue
608 
609 c - At this point, I've read ONE differential vector
610 c - file into RAM and identified the cell of each
611 c - entry.
612 
613  nkt = ikt
614  npid = ipid
615 
616  rms0 = dsqrt(rms0/nkt)
617  rmsm = dsqrt(rmsm/nkt)
618 
619  if(iloop.eq.1)nrmslat = nkt
620  if(iloop.eq.2)nrmslon = nkt
621  if(iloop.eq.3)nrmseht = nkt
622 
623 c - Use the RMS value to compute scales needed for our output vector file.
624 c - Why not AVE? Because the AVE is expected to be VERY close to zero
625 c - but RMS represents a better overall level of disagreement.
626 
627 c iq0 = floor(log10(rms0))
628 c qq0 = 10.d0**(iq0-1)
629 c lorvog0 = MultiplierLorvog*qq0*nint(rms0/qq0)
630  lorvog0 = onzd2(multiplierlorvog*rms0)
631  g02pc = lorvopc / lorvog0
632 
633 c iqm = floor(log10(rmsm))
634 c qqm = 10.d0**(iqm-1)
635 c lorvogm = MultiplierLorvog*qqm*nint(rmsm/qqm)
636  lorvogm = onzd2(multiplierlorvog*rmsm)
637  gm2pc = lorvopc / lorvogm
638 
639 c - 2015 10 09
640  if(iloop.eq.1)then
641  basedd(1) = rms0
642  basedd(4) = rmsm
643  endif
644  if(iloop.eq.2)then
645  basedd(2) = rms0
646  basedd(5) = rmsm
647  endif
648 
649 
650  write(6,2004) nkt,npid,igridsec,ncells
651  2004 format(
652  *6x,'myrms.f: Done with file ',/,
653  *6x,'myrms.f: Points in File : ',i10,/,
654  *6x,'myrms.f: Points within Grid Bounds : ',i10,/,
655  *6x,'myrms.f: Cell Size (Arcseconds) : ',i10,/,
656  *6x,'myrms.f: Number of Cells with Data : ',i10)
657  write(6,2005)
658  2005 format(6x,'myrms.f: Begin RMS computations')
659 
660 c - Sort all of our data (nkt values) by their poscode
661  write(6,2020)
662  2020 format(6x,'myrms.f : Sorting data...')
663  call indexxi(nkt,max,whichcell,indx)
664 
665 c - Spit out our data in WHICHCELL order
666 c do 400 i=1,nkt
667 c j = indx(i)
668 c icell = whichcell(j)
669 c if(mod(i,1000).eq.0)then
670 c write(6,2010)cards(j),icell,ilapcell(icell),
671 c * ilopcell(icell),poscode(icell)
672 c endif
673 c 400 continue
674  2010 format(i8,1x,a80,1x,4(i10))
675 
676 c - 2015/11/06: Change from average lat/lon to
677 c - center of cell for registration of RMS vector,
678 c - as per discussions with Andria
679 
680 c - Now go through each cell and compute
681 c - the average latitude, average longitude
682 c - and RMS value. As each alat/alon/rval is found,
683 c - put it in the appropriate output vector file.
684 c - Change as of 10/28/2015: No longer using
685 c - average lat/lon, but rather center of cell.
686 
687  inumlo = 0
688  inumhi = 0
689  ikt = 0
690 
691  if(iloop.eq.1)then
692  write(6,2021)trim(gfnvsrddlat),trim(gfnssrddlat)
693  write(6,2021)trim(gfnvmrddlat),trim(gfnsmrddlat)
694  endif
695  if(iloop.eq.2)then
696  write(6,2021)trim(gfnvsrddlon),trim(gfnssrddlon)
697  write(6,2021)trim(gfnvmrddlon),trim(gfnsmrddlon)
698  endif
699  if(iloop.eq.3)then
700  write(6,2021)trim(gfnvmrddeht),trim(gfnsmrddeht)
701  endif
702 
703  2021 format(6x,'myrms.f : ',
704  * 'Populating RMS diff vec file: ',a,/,
705  * 6x,'myrms.f : ',
706  * 'Populating RMS diff vec surface-ready file: ',a)
707 
708  ifileout1 = 40+iloop ! DD vectors, primary units
709  ifileout3 = 50+iloop ! DD coverage
710  ifileout2 = 70+iloop ! DD vectors for surface, primary units
711 
712  do 401 icell=1,ncells
713  inumlo = inumhi + 1
714  inumhi = inumlo + ppcell(icell) - 1
715 
716 c - 10/28/2015: removed...useless, right?
717 c do 402 jpt=1,ppcell(icell)
718 c ikt = ikt + 1
719 c j = indx(ikt)
720 c 402 continue
721 
722  call getrms(z0,max,inumlo,inumhi,indx,
723  * maxppcell,xlat,xlon,alat,alon,rval0)
724 
725 c - 01/21/2016: Returned to use of AVE lat/lon for registering RMS vectors
726 c - 10/28/2015: Use center of cell
727 c ila = ilapcell(icell)
728 c ilo = ilopcell(icell)
729 c glacc = glamn + (ila-1)*dgla + (dgla/2.d0)
730 c glocc = glomn + (ilo-1)*dglo + (dglo/2.d0)
731 c alat = glacc
732 c alon = glocc
733 
734  if (iloop.eq.1)then
735  rvalm = rval0 * s2m
736  elseif(iloop.eq.2)then
737  coslat = dcos(alat*d2r)
738  rvalm = rval0 * s2m * coslat
739  else
740  rvalm = rval0
741  endif
742  vc0 = dabs(rval0 * g02pc)
743  vcm = dabs(rvalm * gm2pc)
744 
745 c - For vector plotting:
746  write(ifileout1 ,2101)alon,alat,az,vc0,rval0,rvalm
747  if(iloop.lt.3)
748  * write(ifileout1+5,2101)alon,alat,az,vcm,rval0,rvalm
749  2101 format(f16.10,1x,f15.10,1x,f6.2,1x,
750  * f12.2,1x,f9.5,1x,f9.3)
751 
752 c - For coverage plotting:
753  write(ifileout3,2103)alon,alat,1.0
754  2103 format(f16.10,1x,f15.10,1x,f6.2)
755 
756 c - For use in surface for gridding:
757  write(ifileout2 ,2102)alon,alat,rval0
758  if(iloop.lt.3)
759  * write(ifileout2+5,2102)alon,alat,rvalm
760  2102 format(f16.10,1x,f15.10,1x,f10.5)
761 
762  401 continue
763 
764  2001 continue
765 
766 c -------------------------------------------------
767 c - 2015 10 09
768 c - Spin through the newly created RMS DD vectors in
769 c - lat/lon (in sec and meters) and create an RMS DD
770 c - vector file in HOR (in sec and meters)
771 c
772 c - Do NOT create this from the "add" horizontal
773 c - files, but rather from the newly created "rdd"
774 c - lat and lon files.
775 c -------------------------------------------------
776 
777  baseddhors = sqrt(basedd(1)**2+basedd(2)**2)
778  baseddhorm = sqrt(basedd(4)**2+basedd(5)**2)
779 
780 c iqhorddm = floor(log10(baseddhorm))
781 c qqhorddm = 10.d0**(iqhorddm-1)
782 c lorvoghorddm = MultiplierLorvog*qqhorddm*nint(baseddhorm/qqhorddm)
783  lorvoghorddm = onzd2(multiplierlorvog*baseddhorm)
784  gm2pchordd = lorvopc / lorvoghorddm
785 
786 c iqhordds = floor(log10(baseddhors))
787 c qqhordds = 10.d0**(iqhordds-1)
788 c lorvoghordds = MultiplierLorvog*qqhordds*nint(baseddhors/qqhordds)
789  lorvoghordds = onzd2(multiplierlorvog*baseddhors)
790  gs2pchordd = lorvopc / lorvoghordds
791 
792  write(6,2504)
793  2504 format
794  *(6x,'myrms.f: Populating RMS dd horizontal vector files')
795  iflats = 41
796  iflons = 42
797  iflatm = 46
798  iflonm = 47
799  ifhors = 44
800  ifhorm = 45
801  rewind(iflats)
802  rewind(iflons)
803  rewind(iflatm)
804  rewind(iflonm)
805  2503 read(iflats,2101,end=2502)xlo1,xla1,az1,vc1,xs1,xm1
806  read(iflons,2101)xlo2,xla2,az2,vc2,xs2,xm2
807  if(xlo1.ne.xlo2)stop 10501
808  if(xla1.ne.xla2)stop 10502
809 c if(az1.ne.90.00)stop 10503
810 c if(az2.ne. 0.00)stop 10504
811  azhor = datan2(xm2,xm1)/d2r
812  if(azhor.lt.0)azhor = azhor + 360.d0
813  xshor = dsqrt(xs1**2 + xs2**2)
814  xmhor = dsqrt(xm1**2 + xm2**2)
815  vchors = xshor * gs2pchordd
816  vchorm = xmhor * gm2pchordd
817  write(ifhors,2101)xlo1,xla1,azhor,vchors,xshor,xmhor
818  write(ifhorm,2101)xlo1,xla1,azhor,vchorm,xshor,xmhor
819  goto 2503
820  2502 continue
821 
822 c -------------------------------------------------------
823 c - Based on everything we have so far, put a bunch
824 c - of "surface" calls into the GMT batch file.
825 c - These will be to turn the RMS'd differential vector data
826 c - into grids. DO NOT GENERATE A CALL TO SURFACE
827 c - IF THE NUMBER OF RMS'd DATA IS ZERO.
828 
829 c - Because "surface", as part of GMT, returns its
830 c - own binary grid format (called ".grd" herein), it must be
831 c - converted to ".b" format. The easiest way to
832 c - do so is to use the GMT built-in routine "grd2xyz"
833 c - with the "-bos" extension to create a binary XYZ
834 c - list file. Then run Dennis's homemade "xyz2b.for"
835 c - routine to finally arrive at the ".b" binary grid format.
836 c
837 c - 2015/11/06: Updated to put the ".09." in the names
838 c -------------------------------------------------------
839  cmidlat=dcos(((glamn+glamx)/2.d0)*d2r)
840  rfnvsrddlat = 'vsrddlat.'//trim(suffix2t09)//'.grd'
841  rfnvsrddlon = 'vsrddlon.'//trim(suffix2t09)//'.grd'
842  rfnvmrddeht = 'vmrddeht.'//trim(suffix2t09)//'.grd'
843  rfnvmrddlat = 'vmrddlat.'//trim(suffix2t09)//'.grd'
844  rfnvmrddlon = 'vmrddlon.'//trim(suffix2t09)//'.grd'
845 
846  zfnvsrddlat = 'vsrddlat.'//trim(suffix2t09)//'.xyz'
847  zfnvsrddlon = 'vsrddlon.'//trim(suffix2t09)//'.xyz'
848  zfnvmrddeht = 'vmrddeht.'//trim(suffix2t09)//'.xyz'
849  zfnvmrddlat = 'vmrddlat.'//trim(suffix2t09)//'.xyz'
850  zfnvmrddlon = 'vmrddlon.'//trim(suffix2t09)//'.xyz'
851 
852  bfnvsrddlat = 'vsrddlat.'//trim(suffix2t09)//'.b'
853  bfnvsrddlon = 'vsrddlon.'//trim(suffix2t09)//'.b'
854  bfnvmrddeht = 'vmrddeht.'//trim(suffix2t09)//'.b'
855  bfnvmrddlat = 'vmrddlat.'//trim(suffix2t09)//'.b'
856  bfnvmrddlon = 'vmrddlon.'//trim(suffix2t09)//'.b'
857 
858 c - Due to a bug in GMT, the call will use "-I*m" rather
859 c - than "-I*s". As such, convert igridsec to xgridmin.
860  xgridmin = dble(igridsec)/60.d0
861 
862 c - Do NOT generate a call to surface if there is no data
863 c - to grid.
864 
865 c - Call to grid the RMS'd latitudes
866  if(nrmslat.ne.0)then
867  write(99,501)trim(gfnssrddlat),glomn,glomx,glamn,glamx,
868  * xgridmin,trim(rfnvsrddlat),cmidlat
869  write(99,501)trim(gfnsmrddlat),glomn,glomx,glamn,glamx,
870  * xgridmin,trim(rfnvmrddlat),cmidlat
871  endif
872 
873 c - Call to grid the RMS'd longitudes
874  if(nrmslon.ne.0)then
875  write(99,501)trim(gfnssrddlon),glomn,glomx,glamn,glamx,
876  * xgridmin,trim(rfnvsrddlon),cmidlat
877  write(99,501)trim(gfnsmrddlon),glomn,glomx,glamn,glamx,
878  * xgridmin,trim(rfnvmrddlon),cmidlat
879  endif
880 
881 c - Call to grid the RMS'd ellipsoid heights
882  if(nrmseht.ne.0)
883  *write(99,501)trim(gfnsmrddeht),glomn,glomx,glamn,glamx,
884  *xgridmin,trim(rfnvmrddeht),cmidlat
885 
886 c - Calls to convert ".grd" to ".xyz"
887  if(nrmslat.ne.0)then
888  write(99,502)trim(rfnvsrddlat),trim(zfnvsrddlat)
889  write(99,502)trim(rfnvmrddlat),trim(zfnvmrddlat)
890  endif
891 
892  if(nrmslon.ne.0)then
893  write(99,502)trim(rfnvsrddlon),trim(zfnvsrddlon)
894  write(99,502)trim(rfnvmrddlon),trim(zfnvmrddlon)
895  endif
896  if(nrmseht.ne.0)
897  *write(99,502)trim(rfnvmrddeht),trim(zfnvmrddeht)
898 
899 c - Calls to convert ".xyz" to ".b"
900  if(nrmslat.ne.0)then
901  write(99,503)trim(zfnvsrddlat),trim(bfnvsrddlat)
902  write(99,503)trim(zfnvmrddlat),trim(bfnvmrddlat)
903  endif
904  if(nrmslon.ne.0)then
905  write(99,503)trim(zfnvsrddlon),trim(bfnvsrddlon)
906  write(99,503)trim(zfnvmrddlon),trim(bfnvmrddlon)
907  endif
908  if(nrmseht.ne.0)
909  *write(99,503)trim(zfnvmrddeht),trim(bfnvmrddeht)
910 
911 c - Changed to T=0.9 on 10/28/2015
912  501 format(
913  *'surface ',a,' -R',f9.5,'/',f9.5,'/',sp,f9.5,'/',f9.5,s,
914  *' -I',f0.2,'m -G',a,' -T0.9 -A',s,f6.4,' -C0.01 -V -Lld')
915 
916 c 501 format(
917 c *'surface ',a,' -R',f9.5,'/',f9.5,'/',sp,f9.5,'/',f9.5,s,
918 c *' -I',f0.2,'m -G',a,' -T0.4 -A',s,f6.4,' -C0.01 -V -Lld')
919 c 501 format(
920 c *'surface ',a,' -R',f9.5,'/',f9.5,'/',sp,f9.5,'/',f9.5,s,
921 c *' -I',f0.2,'m -G',a,' -T0.4 -A',s,f6.4,' -C0.01 -V')
922  502 format(
923  *'grd2xyz ',a,' -bo3f > ',a)
924  503 format(
925  *'xyz2b << !',/,
926  *a,/,a,/,'!')
927 
928 c --------------------------------------------------------------
929 c - GMT Batch file: CREATE TRANSFORMATION ERROR GRID
930 c - Added 11/9/2015
931 c
932 c - See DRU-11, p. 145-148: The total transformation error
933 c - grid (representing a "standard deviation of the transformation
934 c - at any grid location") will be a combination of two grids
935 c - that have been called (in shorthand):
936 c 1) The "method noise" grid
937 c 2) The "data noise" grid
938 c * The "method noise" grid represents the noise that comes
939 c from not knowing the perfect tension at which to pull a
940 c transformation grid sheet. It was created in batch
941 c file "gmtbat02...", as created by mymedian5.f
942 c * The "data noise" grid represents the RMS mismatch between
943 c all non-outlier vectors (both kept and dropped) and the
944 c transformation grid (as pulled at T=0.4). It was created
945 c in batch file "gmtbat05..." as created by myrms.f.
946 c The final "transformation error grid" will be a
947 c sort of convolution of the two above grids, as follows:
948 c Let "TE(i,j)" be the transformation error at some
949 c grid node "i,j", and "MN(i,j)" be the method noise
950 c at grid node i,j and "DN(i,j)" be the data noise at
951 c grid node i,j. All three should be in the same units
952 c (either meters or arcseconds). The final "TE" grid
953 c will have these values at every grid node:
954 c TE(i,j) = SQRT[ MN(i,j)**2 + DN(i,j)**2 ]
955 c --------------------------------------------------------------
956 c - The "method noise" grids
957  sadbfnvmtcdlat1000 = 'vmtcdlat.'//trim(suffix2d3)//'.b'
958  sadbfnvstcdlat1000 = 'vstcdlat.'//trim(suffix2d3)//'.b'
959  sadbfnvmtcdlon1000 = 'vmtcdlon.'//trim(suffix2d3)//'.b'
960  sadbfnvstcdlon1000 = 'vstcdlon.'//trim(suffix2d3)//'.b'
961  sadbfnvmtcdeht1000 = 'vmtcdeht.'//trim(suffix2d3)//'.b'
962 
963 c - The "total error" grids in ".b" format
964  bfnvsetelat ='vsetelat.'//trim(suffix2)//'.b'
965  bfnvsetelon ='vsetelon.'//trim(suffix2)//'.b'
966  bfnvmetelat ='vmetelat.'//trim(suffix2)//'.b'
967  bfnvmetelon ='vmetelon.'//trim(suffix2)//'.b'
968  bfnvmeteeht ='vmeteeht.'//trim(suffix2)//'.b'
969 
970 c - The "total error" grids in ".grd" format
971  rfnvsetelat ='vsetelat.'//trim(suffix2)//'.grd'
972  rfnvsetelon ='vsetelon.'//trim(suffix2)//'.grd'
973  rfnvmetelat ='vmetelat.'//trim(suffix2)//'.grd'
974  rfnvmetelon ='vmetelon.'//trim(suffix2)//'.grd'
975  rfnvmeteeht ='vmeteeht.'//trim(suffix2)//'.grd'
976 
977 
978  if(nlat.ne.0)then
979 c------------------
980 c - LATITUDE/METERS
981 c------------------
982 c - Square Method Noise:
983  write(99,801)trim(sadbfnvmtcdlat1000),
984  * trim(sadbfnvmtcdlat1000),
985  * trim(sadbfnvmtcdlat1000)
986 c - Square Data Noise:
987  write(99,802)trim(bfnvmrddlat),trim(bfnvmrddlat),
988  * trim(bfnvmrddlat)
989 c - Add the two squares together:
990  write(99,803)
991 c - Square root of the sum to give the final total transformation error grid
992  write(99,804)trim(bfnvmetelat),trim(bfnvmetelat),
993  * trim(bfnvmetelat)
994 c - Remove all dummy files
995  write(99,805)
996 c------------------
997 c - LATITUDE/ARCSECONDS
998 c------------------
999 c - Square Method Noise:
1000  write(99,801)trim(sadbfnvstcdlat1000),
1001  * trim(sadbfnvstcdlat1000),
1002  * trim(sadbfnvstcdlat1000)
1003 c - Square Data Noise:
1004  write(99,802)trim(bfnvsrddlat),trim(bfnvsrddlat),
1005  * trim(bfnvsrddlat)
1006 c - Add the two squares together:
1007  write(99,803)
1008 c - Square root of the sum to give the final total transformation error grid
1009  write(99,804)trim(bfnvsetelat),trim(bfnvsetelat),
1010  * trim(bfnvsetelat)
1011 c - Remove all dummy files
1012  write(99,805)
1013  endif
1014 
1015  if(nlon.ne.0)then
1016 c------------------
1017 c - LONGITUDE/METERS
1018 c------------------
1019 c - Square Method Noise:
1020  write(99,801)trim(sadbfnvmtcdlon1000),
1021  * trim(sadbfnvmtcdlon1000),
1022  * trim(sadbfnvmtcdlon1000)
1023 c - Square Data Noise:
1024  write(99,802)trim(bfnvmrddlon),trim(bfnvmrddlon),
1025  * trim(bfnvmrddlon)
1026 c - Add the two squares together:
1027  write(99,803)
1028 c - Square root of the sum to give the final total transformation error grid
1029  write(99,804)trim(bfnvmetelon),trim(bfnvmetelon),
1030  * trim(bfnvmetelon)
1031 c - Remove all dummy files
1032  write(99,805)
1033 c------------------
1034 c - LONGITUDE/ARCSECONDS
1035 c------------------
1036 c - Square Method Noise:
1037  write(99,801)trim(sadbfnvstcdlon1000),
1038  * trim(sadbfnvstcdlon1000),
1039  * trim(sadbfnvstcdlon1000)
1040 c - Square Data Noise:
1041  write(99,802)trim(bfnvsrddlon),trim(bfnvsrddlon),
1042  * trim(bfnvsrddlon)
1043 c - Add the two squares together:
1044  write(99,803)
1045 c - Square root of the sum to give the final total transformation error grid
1046  write(99,804)trim(bfnvsetelon),trim(bfnvsetelon),
1047  * trim(bfnvsetelon)
1048 c - Remove all dummy files
1049  write(99,805)
1050  endif
1051 
1052  if(neht.ne.0)then
1053 c------------------
1054 c - ELLIPSOID HEIGHT/METERS
1055 c------------------
1056 c - Square Method Noise:
1057  write(99,801)trim(sadbfnvmtcdeht1000),
1058  * trim(sadbfnvmtcdeht1000),
1059  * trim(sadbfnvmtcdeht1000)
1060 c - Square Data Noise:
1061  write(99,802)trim(bfnvmrddeht),trim(bfnvmrddeht),
1062  * trim(bfnvmrddeht)
1063 c - Add the two squares together:
1064  write(99,803)
1065 c - Square root of the sum to give the final total transformation error grid
1066  write(99,804)trim(bfnvmeteeht),trim(bfnvmeteeht),
1067  * trim(bfnvmeteeht)
1068 c - Remove all dummy files
1069  write(99,805)
1070  endif
1071 
1072 
1073  801 format(
1074  *'# ------------------------------',/,
1075  *'# Squaring the Method Noise Grid: ',a,' = dummy1',/,
1076  *'# ------------------------------',/,
1077  *'echo Squaring the Method Noise Grid: ',a,' = dummy1',/,
1078  *'gsqr << !',/,
1079  *a,/,'dummy1',/,'!')
1080 
1081  802 format(
1082  *'# ------------------------------',/,
1083  *'# Squaring the Data Noise Grid: ',a,' = dummy2',/,
1084  *'# ------------------------------',/,
1085  *'echo Squaring the Data Noise Grid: ',a,' = dummy2',/,
1086  *'gsqr << !',/,
1087  *a,/,'dummy2',/,'!')
1088  803 format(
1089  *'# ------------------------------',/,
1090  *'# Adding dummy1 and dummy2 = dummy3',/,
1091  *'# ------------------------------',/,
1092  *'echo Adding dummy1 and dummy2 = dummy3',/,
1093  *'addem << !',/,
1094  *'dummy1',/,'dummy2',/,'dummy3',/,'!')
1095  804 format(
1096  *'# ------------------------------',/,
1097  *'# SquareRoot dummy3 to get Trans. Error Grid: ',a,/,
1098  *'# ------------------------------',/,
1099  *'echo SquareRoot dummy3 to get Trans. Error Grid: ',a,/,
1100  *'gsqrt << !',/,
1101  *'dummy3',/,a,/,'!')
1102  805 format(
1103  *'# ------------------------------',/,
1104  *'# Removing dummy1, dummy2, dummy3',/,
1105  *'# ------------------------------',/,
1106  *'echo Removing dummy1, dummy2, dummy3',/,
1107  *'rm -f dummy1',/,
1108  *'rm -f dummy2',/,
1109  *'rm -f dummy3')
1110 
1111 cccccccccccccccccccccccccccccccccccccccccccccccccccccc
1112 c - 2016 07 01 : Mask/MASK/mask for the HARN/FBN/CONUS situation
1113 c - See DRU-12, p. 41
1114 c - Basically: Once the "...ete...b" files are created,
1115 c - move them to be "...ete...b.premask". Then apply
1116 c - the mask to this "premask" grid (densify to 30",
1117 c - convolve with 30" mask, then decimate back to original
1118 c - grid spacing) and give it the standard "...ete...b" file name.
1119 c - In this way, when we convert the ".b" to ".grd" in the
1120 c - next section of code, it'll be for the MASKED version
1121 c - of the ".b" grid (but again, ONLY for the HARN/FBN/CONUS
1122 c - situation)
1123  if(trim(olddtm).eq.'nad83_harn' .and.
1124  * trim(newdtm).eq.'nad83_fbn' .and.
1125  * trim(region).eq.'conus' )then
1126 
1127  write(99,601)
1128 
1129  if(nlat.ne.0)then
1130  write(99,602)trim(bfnvmetelat),
1131  * trim(bfnvmetelat)//'.premask',
1132  * trim(bfnvmetelat)//'.premask',
1133  * trim(bfnvmetelat),
1134  * igridsec/30,igridsec/30
1135 
1136  write(99,602)trim(bfnvsetelat),
1137  * trim(bfnvsetelat)//'.premask',
1138  * trim(bfnvsetelat)//'.premask',
1139  * trim(bfnvsetelat),
1140  * igridsec/30,igridsec/30
1141  endif
1142 
1143  if(nlon.ne.0)then
1144  write(99,602)trim(bfnvmetelon),
1145  * trim(bfnvmetelon)//'.premask',
1146  * trim(bfnvmetelon)//'.premask',
1147  * trim(bfnvmetelon),
1148  * igridsec/30,igridsec/30
1149 
1150  write(99,602)trim(bfnvsetelon),
1151  * trim(bfnvsetelon)//'.premask',
1152  * trim(bfnvsetelon)//'.premask',
1153  * trim(bfnvsetelon),
1154  * igridsec/30,igridsec/30
1155  endif
1156 
1157  if(neht.ne.0)then
1158  write(99,602)trim(bfnvmeteeht),
1159  * trim(bfnvmeteeht)//'.premask',
1160  * trim(bfnvmeteeht)//'.premask',
1161  * trim(bfnvmeteeht),
1162  * igridsec/30,igridsec/30
1163  endif
1164 
1165  endif
1166 
1167 
1168  601 format('echo Applying MASK for HARN FBN CONUS ete grids')
1169  602 format(
1170  *'mv ',a,' ',a,/,
1171  *'regrd2 << !',/,
1172  *a,/,
1173  *'dummy1.b',/,
1174  *'3121',/,
1175  *'7081',/,
1176  *'!',/,
1177  *'convlv << !',/
1178  *'dummy1.b',/,
1179  *'Masks/mask.harnfbn.30.b',/,
1180  *'dummy2.b',/,
1181  *'!',/,
1182  *'decimate << !',/
1183  *'dummy2.b',/,
1184  *a,/,
1185  *i3,/,
1186  *i3,/,
1187  *'!',/,
1188  *'rm -f dummy1.b',/,
1189  *'rm -f dummy2.b')
1190 
1191 c --------------------------------------------------------------
1192 c - GMT Batch file: Convert transformation error grid to "grd"
1193 c - format so I can color plot it later.
1194 c --------------------------------------------------------------
1195 
1196  if(nlat.ne.0)then
1197  write(99,507)trim(bfnvmetelat)
1198  * ,glomn,glomx,glamn,glamx,xgridmin,trim(rfnvmetelat)
1199  write(99,507)trim(bfnvsetelat)
1200  * ,glomn,glomx,glamn,glamx,xgridmin,trim(rfnvsetelat)
1201  endif
1202 
1203  if(nlon.ne.0)then
1204  write(99,507)trim(bfnvmetelon)
1205  * ,glomn,glomx,glamn,glamx,xgridmin,trim(rfnvmetelon)
1206  write(99,507)trim(bfnvsetelon)
1207  * ,glomn,glomx,glamn,glamx,xgridmin,trim(rfnvsetelon)
1208  endif
1209 
1210  if(neht.ne.0)then
1211  write(99,507)trim(bfnvmeteeht)
1212  * ,glomn,glomx,glamn,glamx,xgridmin,trim(rfnvmeteeht)
1213 
1214  endif
1215  507 format(
1216  *'b2xyz << !',/,a,/,'!',/,
1217  *'xyz2grd temp.xyz -R',f9.5,'/',f9.5,'/',sp,f9.5,'/',f9.5,s,
1218  *' -I',f0.2,'m -bi3f -G',a,/,
1219  *'rm -f temp.xyz')
1220 
1221 
1222 
1223 
1224 
1225 
1226 
1227 
1228 
1229 
1230 
1231 
1232 
1233 
1234 
1235  write(99,1031)trim(gmtfile)
1236  1031 format('echo END batch file ',a)
1237  close(99)
1238 
1239  write(6,9999)
1240  9999 format('END program myrms.f')
1241 
1242 
1243 
1244  2006 format('Cell ',i8,' Poscode: ',i12)
1245  2007 format(6x,'Pt : ',i5)
1246  end
1247 c
1248 c -----------------------------------------------
1249 c
1250  subroutine getrms(zs,max,inumlo,inumhi,indx,
1251  *maxppcell,xlat,xlon,alat,alon,rval)
1253 c - As of 10/28/2015, no longer using average
1254 c - lat/lon, but rather center of cell, to
1255 c - register the RMS vector
1256 
1257  real*8 xlat(max),xlon(max),zs(max)
1258  integer*4 indx(max),indx2(maxppcell)
1259  integer*4 inumlo,inumhi
1260 
1261  real*8 alat,alon,rval
1262 
1263 c write(6,1)inumlo,inumhi
1264  1 format('Inside getrms',/,
1265  *'inumlo,inumhi = ',i8,1x,i8)
1266 
1267 c - When the whole set of "zs" data is sorted by
1268 c - "whichcell", then the "indx" values are our
1269 c - key to that sort. The "zs" data remains
1270 c - in "read order" (1-nkt), but the indx values
1271 c - (also in "read order" point to the sorted
1272 c - order.
1273 
1274 c - Because we are NOT attempting any kind of
1275 c - median filter, there is no need to sort
1276 c - the "mini vector" of data in this cell.
1277 c - Just compute the average lat, average lon
1278 c - and RMS value and return.
1279 c - Change as of 10/28/2015: Do not
1280 c - use the avelat/avelon. Instead,
1281 c - register the RMS vector to the center of
1282 c - the cell. (See DRU-11, p. 145)
1283 
1284  rval = 0.d0
1285  alat = 0.d0
1286  alon = 0.d0
1287 
1288 
1289  nval = inumhi-inumlo+1
1290  iq = 0
1291  do 4 i=inumlo,inumhi
1292  iq = iq + 1
1293  rval = rval + zs(indx(i))**2
1294  alat = alat + xlat(indx(i))
1295  alon = alon + xlon(indx(i))
1296  4 continue
1297  rval = dsqrt(rval/nval)
1298  alat = alat/nval
1299  alon = alon/nval
1300 
1301  return
1302  end
1303 
1304  include 'Subs/getgridbounds.f'
1305  include 'Subs/indexxi.for'
1306  include 'Subs/onzd2.f'
1307 
subroutine indexxi(n, nd, arr, indx)
Subroutine to perform ?? indexing on integer data.
Definition: indexxi.for:24
real *8 function onzd2(x)
Function to round a digit to one significant figure (one non zero digit), double precision.
Definition: onzd2.f:36
subroutine getrms(zs, max, inumlo, inumhi, indx, maxppcell, xlat, xlon, alat, alon, rval)
Definition: myrms.f:1252
subroutine getgridbounds(region, xn, xs, xw, xe)
Subroutine to collect up the GRID boundaries for use in creating NADCON 5.
Definition: getgridbounds.f:30
program myrms
Part of the NADCON5 build process, generates gmtbat05
Definition: myrms.f:101