From VisualWorks® NonCommercial, Release 5i.4 of August 9, 2001 on June 12, 2002 at 1:38:43 am
CormasNS.Kernel.SpaceModel import - export
saveAttributesASC: attributes fileParameters: aList
| stream firstValue type firstPatch dicoAttConv patch a c position |
attributes listHolder value
do:
[:att |
stream := ((Cormas mapsPath: self cormasModel class name) asString , '\' , att , 'Cormas.asc') asFilename writeStream.
stream nextPutAll: 'ncols '; nextPut: Character tab; nextPutAll: column printString; nextPutAll: '\' withCRs.
stream nextPutAll: 'nrows '; nextPut: Character tab; nextPutAll: line printString; nextPutAll: '\' withCRs.
stream nextPutAll: 'xllcorner '; nextPut: Character tab; nextPutAll: (aList at: 1); nextPutAll: '\' withCRs.
stream nextPutAll: 'yllcorner '; nextPut: Character tab; nextPutAll: (aList at: 2); nextPutAll: '\' withCRs.
stream nextPutAll: 'cellsize '; nextPut: Character tab; nextPutAll: (aList at: 3); nextPutAll: '\' withCRs.
stream nextPutAll: 'NODATA_value '; nextPut: Character tab; nextPutAll: (aList at: 4); nextPutAll: '\' withCRs.
dicoAttConv := Dictionary new.
firstPatch := self elementaryEntities detect: [:p | (p perform: att asSymbol) isNil not]
ifNone: [nil].
firstPatch isNil
ifTrue: [firstValue := nil]
ifFalse: [firstValue := firstPatch perform: att asSymbol].
firstValue isSymbol
ifTrue:
[type := '(Symbol)'.
dicoAttConv at: att asSymbol put: #asString]
ifFalse: [(firstValue isKindOf: Number)
ifTrue:
[type := '(Number)'.
dicoAttConv at: att asSymbol put: #printString]
ifFalse: [firstValue isString
ifTrue:
[type := '(String)'.
dicoAttConv at: att asSymbol put: #asString]
ifFalse: [(firstValue isKindOf: Boolean)
ifTrue:
[type := '(Boolean)'.
dicoAttConv at: att asSymbol put: #printString]
ifFalse:
[type := '(nil)'.
dicoAttConv at: att asSymbol put: #printString]]]].
1 to: line do: [:i | 1 to: column
do:
[:j |
position := ((i - 1) * column) + j.
patch := self elementaryEntities at: position.
a := att asSymbol.
c := dicoAttConv at: a.
stream nextPutAll: ((patch perform: a)
perform: c).
position \\ column = 0 ifFalse: [stream nextPutAll: ' ']
ifTrue: [stream nextPutAll: '\' withCRs]]].
stream close]