
NB. Createdapp def file is as follows

NB. ====================================================================================================
NB. ====  (1/4) name of application =======
NB./*/APP_FOLDER_NAME/02_04_demo_number_list_reformat_with_file_save_option_added


NB. ====================================================================================================
NB. ====  (2/4) design of HTML doc  =======
NB./*/HTML_TITLE/Text Reformater
NB./*/HTML_REMARK/multiple numbers in the textarea will be reformatted. Select table column number, number of total digit including decimal point  and number of decimal digit. Reformatted result file save option available.

NB./*/HORIZONTALLINE
NB./*/TEXTAREA/00/VERTICAL/150/5/data input area /1.1 20.5 30 40.8 5.5 7.8 80.2
NB./*/HORIZONTALLINE
NB./*/DROPDOWN/00/VERTICAL/number of column of the table /6+6/12+12/1+1/2+2/3+3/4+4/5+5/6+6/7+7/8+8/9+9/10+10/11+11/12+12
NB./*/HORIZONTALLINE
NB./*/CHECKLIST/00/VERTICAL/3/number of total digits including decimal point /6+6/8+8/10+10
NB./*/CHECKLIST/01/HORIZONTAL/3/number of decimal digits /0+0/1+1/2+2
NB./*/HORIZONTALLINE
NB./*/TEXTBOX/00/VERTICAL/20/directory for saving /
NB./*/TEXTBOX/01/VERTICAL/30/result save filename /reformatted_result.txt
NB./*/HORIZONTALLINE
NB./*/RADIOBUTTON/00/HORIZONTAL/result save option /no save+none/new+create/append+append
NB./*/HORIZONTALLINE

NB. ====================================================================================================
NB. ====  (3/4) descrition of J function  =======
NB.define your J function(s) which will be used in YOUR_JOB function

NB. ============================================
replace_CRLF_with_space_in_str_y =: 3 : 0
v =. y
a_result =. ''
lineNo =. 0
total_Ln =. +/CRLF E. y
while. lineNo < total_Ln do.
 aLine =. take_one_line v
 print aLine
 a_result =. a_result, aLine, ' '
 v =. (2 + $ aLine) }. v  NB. drop line + CRLF(2 byte)
 lineNo =. 1 + lineNo
end.
a_result
)

NB. ============================================
reformat_number_list_str_to_matrix_of_column_size_x_str =: 4 : 0
NB.
NB. y is one string with multiple numbers with separator space
a_data =. ". y
a_column =. ". x
a_count =. #a_data
a_sho_int =. <. a_count % a_column
a_amari   =. a_column | a_count
if. a_amari > 0 do.
  tsuika_zero =. 0*i.(a_column - a_amari)
  a_data =. a_data, tsuika_zero
  a_result =. ((a_sho_int +1), a_column)$a_data
else.
  a_result =. (a_sho_int, a_column)$a_data
end.
a_result
)

NB. ====================================================================================================
NB. ====  (4/4) desctiption of your job based on POSTed data as argument of J function =======
YOUR_JOB =: 3 : 0
a_collection =. monitor_entry_ID_values 0 NB.extraction of POSTed data
reply_msg =. 'operation done without error'
reply_msg =. reply_msg, CRLF, CRLF
reply_msg =. reply_msg, a_collection

try. NB. -----
NB. contents of this textarea will be saved in try. block of YOUR_JOB function
a_given_data_str  =. TEXTAREA_00_VALUE, CRLF
a_table_column    =. DROPDOWN_00_VALUE

a_total_digits_including_decimal_point   =. CHECKLIST_00_VALUE
a_decimal_digits =. CHECKLIST_01_VALUE 

a_result_file_directory =. INSTALL_DIR,'/usr'
TEXTBOX_00_VALUE =: a_result_file_directory

a_result_file_name      =. TEXTBOX_01_VALUE
a_result_save_option    =. RADIO_00_VALUE

print a_given_data_str, CRLF

a_given_data_str_CRLF_replaced_with_space        =: replace_CRLF_with_space_in_str_y a_given_data_str
print 'a_given_data_str_CRLF_replaced_with_space =. replace_CRLF_with_space_in_str_y a_given_data_str done'

a_reformated_data =: a_table_column reformat_number_list_str_to_matrix_of_column_size_x_str a_given_data_str_CRLF_replaced_with_space

print a_table_column,' ','reformat_number_list_str_to_matrix_of_column_size_x_str a_given_data_str_CRLF_replaced_with_space done'

a_format                  =. a_total_digits_including_decimal_point,'j',a_decimal_digits, '": '
a_reformat_cmd            =. a_format,' ', 'a_reformated_data'
a_reformated_data_revised =. ". a_reformat_cmd

print 'a_reformat_cmd is ', a_reformat_cmd

NB. this is a matrix with at least one row with a_table_column specified
NB. save the result to a buffer file reformated.txt
a_reformated_data_revised  save_array_number_data_as_text_file 'reformated.txt'
print 'a_reformated_data save_array_number_data_as_text_file reformated.txt done', CRLF

a_result =. rff 'reformated.txt'
print a_result, CRLF

a_save_location =. a_result_file_name

if. a_result_save_option -: 'create' do.
  a_result wtf_usr a_save_location
  reply_msg =. reply_msg, CRLF, a_result, CRLF, 'result has been saved   to ', a_save_location, CRLF
  a_file_content =. rff_usr a_save_location
  reply_msg =. reply_msg, CRLF, CRLF, 'content of file is as follows', CRLF, a_file_content, CRLF
  
end.

if. a_result_save_option -: 'append' do.
  a_result append_it_usr a_save_location
  reply_msg =. reply_msg, CRLF, a_result, CRLF, 'result has been appended to ', a_save_location, CRLF
  a_file_content =. rff_usr a_save_location
  reply_msg =. reply_msg, CRLF, CRLF, 'content of file is as follows', CRLF, a_file_content, CRLF
end.

if. a_result_save_option -: 'none' do.
  reply_msg =. reply_msg, CRLF, a_result
end.

catch. NB. -----
reply_msg =. 'error occured during the operation'
end. NB. -----
reply_msg
)
NB. end of creation
