Changeset 381 for trunk/readexp.tcl


Ignore:
Timestamp:
Dec 4, 2009 5:05:13 PM (11 years ago)
Author:
toby
Message:

# on 2001/04/17 22:44:59, toby did:
revise to use CR/LF for all platforms

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/readexp.tcl

    • Property rcs:date changed from 2001/04/03 19:10:54 to 2001/04/17 22:44:59
    • Property rcs:lines changed from +8 -3 to +19 -33
    • Property rcs:rev changed from 1.24 to 1.25
    r376 r381  
    55#  The GSAS data is read from an EXP file.
    66#   ... reading an EXP file into an array
     7# returns -1 on error
     8# returns 0 if the file is old-style UNIX format (no CR/LF)
     9# returns 1 if the file is 80 char/line + cr/lf
     10# returns 2 if the file is sequential but not fixed-record length
    711proc expload {expfile} {
    812    global exparray
     
    1216                "Unable to open file $expfile" error 0 "Exit" ; return -1
    1317    }
     18    fconfigure $fil -translation lf
    1419    set len [gets $fil line]
    1520    if {[string length $line] != $len} {
     
    3843        while {$len > 0} {
    3944            set key [string range $line 0 11]
    40             set exparray($key) [string range $line 12 end]
     45            set exparray($key) [string range $line 12 79]
     46            if {$len != 81 || [string range $line end end] != "\r"} {set fmt 2}
    4147            set len [gets $fil line]
    4248        }
     
    962968                    makeexprec "${key} EPHAS"
    963969                    # expedt defaults this to "F", but I think "T" is better
    964                     global tcl_platform
    965                     if {[string match "IRIX*" $tcl_platform(os)]} {
    966                         setexp "${key} EPHAS" "T" 50 1
    967                     } else {
    968                         setexp "${key} EPHAS" "Y" 50 1
    969                     }
     970                    setexp "${key} EPHAS" "Y" 50 1
    970971                    if $expgui(debug) {puts "Warning: creating a ${key} EPHAS record"}
    971972                }
     
    981982            }
    982983            foextract-set {
    983                 global tcl_platform
    984                 if {[string match "IRIX*" $tcl_platform(os)]} {
    985                     if $value {
    986                         setexp "${key} EPHAS" "T" 50 1
    987                     } else {
    988                         setexp "${key} EPHAS" "F" 50 1
    989                     }       
    990                 } else {
    991984                # the flag has changed to "Y/N" in the latest versions
    992985                # of GSAS
    993                     if $value {
    994                         setexp "${key} EPHAS" "Y" 50 1
    995                     } else {
    996                         setexp "${key} EPHAS" "N" 50 1
    997                     }
     986                if $value {
     987                    setexp "${key} EPHAS" "Y" 50 1
     988                } else {
     989                    setexp "${key} EPHAS" "N" 50 1
    998990                }
    999991            }
     
    20112003# write the .EXP file
    20122004proc expwrite {expfile} {
    2013     global tcl_platform exparray
     2005    global exparray
    20142006    set blankline \
    20152007     "                                                                        "
    20162008    set fp [open ${expfile} w]
     2009    fconfigure $fp -translation crlf
    20172010    set keylist [lsort [array names exparray]]
    20182011    # reorder the keys so that VERSION comes 1st
    20192012    set pos [lsearch -exact $keylist {     VERSION}]
    20202013    set keylist "{     VERSION} [lreplace $keylist $pos $pos]"
    2021     if {$tcl_platform(platform) == "windows"} {
    2022         foreach key $keylist {
    2023             puts $fp [string range \
    2024                     "$key$exparray($key)$blankline" 0 79]
    2025         }
    2026     } else {
    2027         foreach key $keylist {
    2028             puts -nonewline $fp [string range \
    2029                     "$key$exparray($key)$blankline" 0 79]
    2030         }
     2014    foreach key $keylist {
     2015        puts $fp [string range \
     2016                "$key$exparray($key)$blankline" 0 79]
    20312017    }
    20322018    close $fp
Note: See TracChangeset for help on using the changeset viewer.