From VisualWorks® NonCommercial, 7.3 of December 3, 2004 on May 9, 2007 at 1:54:39 am
CormasNS.Kernel.SpaceModel import - export
saveCurrentStepAttributesASC: attributes fileParameters: aList
| stream firstValue type firstPatch dicoAttConv patch a c position |
attributes do:
[:att |
stream := ((Cormas mapsPath: self cormasModel class name) asString , '\'
, att , 'Cormas' , self cormasModel timeStep printString, '.asc')
asFilename writeStream.
stream
nextPutAll: 'ncols ';
nextPut: Character space;
nextPutAll: column printString;
nextPutAll: '\' withCRs.
stream
nextPutAll: 'nrows ';
nextPut: Character space;
nextPutAll: line printString;
nextPutAll: '\' withCRs.
stream
nextPutAll: 'xllcorner ';
nextPut: Character space.
xll isNil
ifTrue: [stream nextPutAll: (aList at: 1)]
ifFalse: [stream nextPutAll: xll printString].
stream nextPutAll: '\' withCRs.
stream
nextPutAll: 'yllcorner ';
nextPut: Character space.
yll isNil
ifTrue: [stream nextPutAll: (aList at: 2)]
ifFalse: [stream nextPutAll: yll printString].
stream nextPutAll: '\' withCRs.
stream
nextPutAll: 'cellSize ';
nextPut: Character space.
cellSize isNil
ifTrue: [stream nextPutAll: (aList at: 4)]
ifFalse: [stream nextPutAll: cellSize printString].
stream nextPutAll: '\' withCRs.
stream
nextPutAll: 'NODATA_value ';
nextPut: Character space;
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]