1 | ;------------------------------------------------------------ |
---|
2 | ;------------------------------------------------------------ |
---|
3 | ;------------------------------------------------------------ |
---|
4 | ;+ |
---|
5 | ; @file_comments |
---|
6 | ; read the old binary direct access file that contains the |
---|
7 | ; distance to the coast in OPA. |
---|
8 | ; based on the OPA subroutines dtacof and parctl |
---|
9 | ; |
---|
10 | ; @categories for OPA before NetCDF |
---|
11 | ; |
---|
12 | ; |
---|
13 | ; @returns a structure that contains two elements: tdistcoast (the |
---|
14 | ; distance for the t-points) and fdiscoast (the distance for the |
---|
15 | ; f-points). |
---|
16 | ; |
---|
17 | ; @history Sebastien Masson (smasson\@lodyc.jussieu.fr) |
---|
18 | ; June, 2002 |
---|
19 | ;- |
---|
20 | ;------------------------------------------------------------ |
---|
21 | ;------------------------------------------------------------ |
---|
22 | ;------------------------------------------------------------ |
---|
23 | |
---|
24 | FUNCTION read3fromopa, unit, params, num |
---|
25 | offset=params.reclen*params.jpk*(num-1L) |
---|
26 | a=assoc(unit,dblarr(params.jpiglo,params.jpjglo,params.jpk,/nozero),offset) |
---|
27 | b = a[0] |
---|
28 | return, b |
---|
29 | end |
---|
30 | |
---|
31 | ;+ |
---|
32 | ; @param filename {in}{required} filename (with the whole path if necessary) |
---|
33 | ; @param jpiglo {in}{required} |
---|
34 | ; @param jpjglo {in}{required} |
---|
35 | ; @param jpk {in}{required} |
---|
36 | ; dimensions of the opa grid |
---|
37 | ; @keyword IBLOC ibloc size, default: ibloc = 4096L |
---|
38 | ; @keyword JPBYT jpbyt size, default: jpbyt = 8L |
---|
39 | ; @keyword NUMREC number of records in the file. default: numrec = 19L*jpk |
---|
40 | ; @history Sebastien Masson (smasson\@lodyc.jussieu.fr) |
---|
41 | ; June, 2002 |
---|
42 | ;- |
---|
43 | FUNCTION readoldopadistcoast, filename, jpiglo, jpjglo, jpk, IBLOC = ibloc, JPBYT = jpbyt, NUMREC = numrec |
---|
44 | ; |
---|
45 | iname_file = findfile(filename) |
---|
46 | if iname_file[0] EQ '' then begin |
---|
47 | print, 'Bad file name' |
---|
48 | return, -1 |
---|
49 | ENDIF ELSE iname_file = iname_file[0] |
---|
50 | ; open the file |
---|
51 | openr,numcost , iname_file, /get_lun, /swap_if_little_endian |
---|
52 | ; check the size of the file |
---|
53 | filepamameters = fstat(numcost) |
---|
54 | ; defaut parameter definition for ORCA2 |
---|
55 | IF keyword_set(ibloc) THEN ibloc = long(ibloc) ELSE ibloc = 4096L |
---|
56 | jpiglo = long(jpiglo) |
---|
57 | jpjglo = long(jpjglo) |
---|
58 | jpk = long(jpk) |
---|
59 | IF keyword_set(jpbyt) THEN jpbyt = long(jpbyt) ELSE jpbyt = 8L |
---|
60 | ; record length computation |
---|
61 | reclen = ibloc*((jpiglo*jpjglo*jpbyt-1 )/ibloc+1) |
---|
62 | ; number of records |
---|
63 | IF keyword_set(numrec) THEN numrec = long(numrec) ELSE numrec = 3L*jpk |
---|
64 | ; difference between the record length and the size of the contened |
---|
65 | ; array. |
---|
66 | toomuch = reclen-jpiglo*jpjglo*jpbyt |
---|
67 | ; expected size computation |
---|
68 | size = numrec*reclen-toomuch |
---|
69 | if size NE filepamameters.size then begin |
---|
70 | print, 'The size of the file is not the expected one!' |
---|
71 | print, 'Check your file or the values of ibloc, jpiglo,' |
---|
72 | print, 'jpjglo, jpk, jpbyt, numrec in this program' |
---|
73 | return, -1 |
---|
74 | endif |
---|
75 | ; first record: six 64-bit integer to read. |
---|
76 | ; default definition |
---|
77 | iimlu = long64(999) |
---|
78 | ijmlu = long64(999) |
---|
79 | ikmlu = long64(999) |
---|
80 | ; read |
---|
81 | readu, numcost, iimlu, ijmlu, ikmlu |
---|
82 | if iimlu NE jpiglo then begin |
---|
83 | print, 'iimlu = '+strtrim(iimlu, 1)+' differs from jpiglo ='+strtrim(jpiglo, 1) |
---|
84 | return, -1 |
---|
85 | endif |
---|
86 | if ijmlu NE jpjglo then begin |
---|
87 | print, 'ijmlu = '+strtrim(ijmlu, 1)+' differs from jpjglo ='+strtrim(jpjglo, 1) |
---|
88 | return, -1 |
---|
89 | endif |
---|
90 | if ikmlu NE jpk then begin |
---|
91 | print, 'ikmlu = '+strtrim(ikmlu, 1)+' differs from jpk ='+strtrim(jpk, 1) |
---|
92 | return, -1 |
---|
93 | endif |
---|
94 | ; other records |
---|
95 | params = {jpiglo:jpiglo, jpjglo:jpjglo, jpk:jpk, reclen:reclen} |
---|
96 | tdistcoast = read3fromopa(numcost, params, 2) |
---|
97 | fdistcoast = read3fromopa(numcost, params, 3) |
---|
98 | ; |
---|
99 | close, numcost |
---|
100 | free_lun, numcost |
---|
101 | |
---|
102 | return, {tdistcoast:tdistcoast, fdistcoast:fdistcoast} |
---|
103 | end |
---|