-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdmwfhr.f
96 lines (96 loc) · 2.58 KB
/
dmwfhr.f
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
SUBROUTINE DM_WFHR ( iflno, fhdnam, rheadr, nword, iret )
C************************************************************************
C* DM_WFHR *
C* *
C* This subroutine writes a real-valued file header to a DM file. The *
C* length of the file header must be less than the length given when *
C* the file was created. When the file header is read, the length *
C* input in this subroutine will be returned. *
C* *
C* DM_WFHR ( IFLNO, FHDNAM, RHEADR, NWORD, IRET ) *
C* *
C* Input parameters: *
C* IFLNO INTEGER File number *
C* FHDNAM CHAR*4 File header name *
C* RHEADR (NWORD) REAL File header *
C* NWORD INTEGER Header length *
C* *
C* Output parameters: *
C* IRET INTEGER Return code *
C* 0 = normal return *
C* -4 = file not open *
C* -6 = write error *
C* -7 = read error *
C* -13 = no write access *
C* -18 = file header too long *
C* -21 = incorrect data type *
C* -29 = invalid file hdr name *
C* -33 = invalid machine *
C** *
C* Log: *
C* M. desJardins/GSFC 4/87 *
C* M. desJardins/NMC 4/91 Check for invalid machine *
C************************************************************************
INCLUDE 'GEMPRM.PRM'
INCLUDE 'dmcmn.cmn'
C
CHARACTER*(*) fhdnam
REAL rheadr (*)
C------------------------------------------------------------------------
C* Check that file is open.
C
CALL DM_CHKF ( iflno, iret )
IF ( iret .ne. 0 ) RETURN
C
C* Check that file was opened with write access.
C
IF ( .not. wflag (iflno) ) THEN
iret = -13
RETURN
END IF
C
C* Check that this is a valid file header name.
C
knt = 0
DO i = 1, kfhdrs ( iflno )
IF ( kfhnam ( i, iflno ) .eq. fhdnam ) knt = i
END DO
C
C* Check for invalid file name.
C
IF ( knt .eq. 0 ) THEN
iret = -29
C
C* Compare length to be written with creation length.
C
ELSE IF ( nword .gt. kfhlen ( knt, iflno ) ) THEN
iret = -18
C
C* Check for valid data type.
C
ELSE IF ( kfhtyp ( knt, iflno ) .ne. MDREAL ) THEN
iret = -21
C
C* Check for correct machine type.
C
ELSE IF ( kmachn ( iflno ) .ne. MTMACH ) THEN
iret = -33
C
C* Compute location to write to file.
C
ELSE
iwrite = kpfile ( iflno ) + 3 * kfhdrs ( iflno )
DO i = 1, knt - 1
iwrite = iwrite + kfhlen ( i, iflno ) + 1
END DO
C
C* Write actual length and then write header.
C
CALL DM_WINT ( iflno, iwrite, 1, nword, iret )
IF ( iret .ne. 0 ) RETURN
iwrite = iwrite + 1
CALL DM_WFLT ( iflno, iwrite, nword, rheadr, iret )
END IF
C*
RETURN
END